How to change a number to superscript in textarea?

D

dalei

When typing several numbers in the textarea of form, I need them change
to superscripts. Could anyone teach me how to ahieve the effects.

Thanks.
 
B

Benjamin Niemann

dalei said:
When typing several numbers in the textarea of form, I need them change
to superscripts. Could anyone teach me how to ahieve the effects.

You can't do this (really) with a textarea. The only exception are
superscript 1, 2 and 3 for which there are characters available in
iso-8859-1 (can be entered with alt-1, -2 and -3 on my keyboard layout).
Don't know, if unicode defines more superscript numbers and if these are
present in commonly used fonts.

Another solution would be to allowed (a subset of) HTML in the text entered,
so a user can enter things like "foo<sup>4711</sup>" - this will only make
sense, if the text is supposed to be displayed as HTML again. And you will
have to worry about various security issues (malicious JS code insertion by
an attacker), so you have to parse the submitted text an filter all HTML
tags that are not whitelisted.

The latter option could be made more comfortable for users with
IE/NS/Firefox and JS enabled by using a so called WYSIWYG component which
replaces the textarea by a "MS Word" style editing area. Such components
are available as open source (http://freshmeat.net/search/?q=wysiwyg+html).
 
D

dalei

Benjamin said:
You can't do this (really) with a textarea. The only exception are
superscript 1, 2 and 3 for which there are characters available in
iso-8859-1 (can be entered with alt-1, -2 and -3 on my keyboard layout).
Don't know, if unicode defines more superscript numbers and if these are
present in commonly used fonts.

Another solution would be to allowed (a subset of) HTML in the text entered,
so a user can enter things like "foo<sup>4711</sup>" - this will only make
sense, if the text is supposed to be displayed as HTML again. And you will
have to worry about various security issues (malicious JS code insertion by
an attacker), so you have to parse the submitted text an filter all HTML
tags that are not whitelisted.

The latter option could be made more comfortable for users with
IE/NS/Firefox and JS enabled by using a so called WYSIWYG component which
replaces the textarea by a "MS Word" style editing area. Such components
are available as open source (http://freshmeat.net/search/?q=wysiwyg+html).

I wonder if this can be achieved with js function. Or can js function
work on input in the textarea. Following is a simple function:

<script>
function sups (mynum) {
document.write ('<sup>' + mynum + '<sup>');
}
sups (2)
</script>

The above or a similar function would turn the 2 into a supscript. But
I have no idea how to make this happen for the textarea.

Dalei
 
B

Benjamin Niemann

dalei said:
I wonder if this can be achieved with js function. Or can js function
work on input in the textarea. Following is a simple function:

<script>
function sups (mynum) {
document.write ('<sup>' + mynum + '<sup>');
}
sups (2)
</script>

The above or a similar function would turn the 2 into a supscript. But
I have no idea how to make this happen for the textarea.

A textarea can - as designed and implemented by all browsers - only display
plain text without any formatting. What you are thinking about is more or
less the way the WYSIWIG editors mentioned above work - they remove the
textarea using JS and replace it by an editable 'subdocument', often an
iframe, that can use all features of a HTML document, but has additionally
a cursor and can be modified. If you want to take this road, try one of the
ready-to-use components instead of inventing your own - there are lots of
cross-browser issues involved.

But beware - I've learned to hate these 'WYSIWYG editors', they produce lots
of junk and hell breaks loose, if someone has the brilliant idea of copying
text from MS Word into such an editor...
 
J

Jukka K. Korpela

Benjamin Niemann said:
You can't do this (really) with a textarea. The only exception are
superscript 1, 2 and 3 for which there are characters available in
iso-8859-1 (can be entered with alt-1, -2 and -3 on my keyboard layout).

The numbers don't change, but the user can type superscript numbers if he
knows how to (e.g., via a Character Map or some other utility).
Don't know, if unicode defines more superscript numbers

It does.
and if these are
present in commonly used fonts.

They aren't.

The real question, as so often, is "why?" - oh, and "what does the question
really mean?" Is this about actually filling out a form (any form), i.e.
browser usage question? Or is it about creating a form with a textarea with
some magic properties with superscripts? In the latter case, what is the
point?
 
N

Neredbojias

With neither quill nor qualm, dalei quothed:
When typing several numbers in the textarea of form, I need them change
to superscripts. Could anyone teach me how to ahieve the effects.

What if someone wants to type an ordinal number into the form?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,764
Messages
2,569,566
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top