|
Posted by Benjamin Niemann on 08/28/05 00:33
dalei wrote:
> Benjamin Niemann wrote:
>> dalei wrote:
>>
>> > 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).
>>
>> --
>> Benjamin Niemann
>> Email: pink at odahoda dot de
>> WWW: http://www.odahoda.de/
>
> 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...
--
Benjamin Niemann
Email: pink at odahoda dot de
WWW: http://www.odahoda.de/
[Back to original message]
|