How to change a number to superscript in textarea?

Discussion in 'HTML' started by dalei, Aug 27, 2005.

  1. dalei

    dalei Guest

    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.
    dalei, Aug 27, 2005
    #1
    1. Advertising

  2. 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/
    Benjamin Niemann, Aug 27, 2005
    #2
    1. Advertising

  3. dalei

    dalei Guest

    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.

    Dalei
    dalei, Aug 27, 2005
    #3
  4. 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/
    Benjamin Niemann, Aug 27, 2005
    #4
  5. Benjamin Niemann <> 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).


    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?

    --
    Yucca, http://www.cs.tut.fi/~jkorpela/
    Pages about Web authoring: http://www.cs.tut.fi/~jkorpela/www.html
    Jukka K. Korpela, Aug 28, 2005
    #5
  6. dalei

    Neredbojias Guest

    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?

    --
    Neredbojias
    Contrary to popular belief, it is believable.
    Neredbojias, Aug 28, 2005
    #6
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. jodleren
    Replies:
    12
    Views:
    1,567
    GTalbot
    Jan 4, 2008
  2. shahid

    subscript and superscript

    shahid, Feb 4, 2009, in forum: C++
    Replies:
    14
    Views:
    7,693
    James Kanze
    Feb 6, 2009
  3. Augustus
    Replies:
    1
    Views:
    340
    Ken Schaefer
    Sep 10, 2003
  4. MBS
    Replies:
    5
    Views:
    279
  5. dalei

    Turning a number to superscript

    dalei, Aug 23, 2005, in forum: Javascript
    Replies:
    8
    Views:
    115
    Robert
    Aug 27, 2005
Loading...

Share This Page