Textbox + Javascript

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Mike Walker

    Textbox + Javascript

    Hi,
    Please can you help me,
    I have seen some free JavaScript that has a text box, with buttons under it
    Bold, Italic, Underline, so when the text in the box is highlighted, it puts
    the HTML code around the selected text.

    But I can not now find it .... do you know where an example is?

    Many thanks
    Mike.


  • kaeli

    #2
    Re: Textbox + Javascript

    In article <6mOXb.6193$vo1 .3313@newsfep4-winn.server.ntl i.net>, mike42
    @ntlworld.com enlightened us with...[color=blue]
    > Hi,
    > Please can you help me,
    > I have seen some free JavaScript that has a text box, with buttons under it
    > Bold, Italic, Underline, so when the text in the box is highlighted, it puts
    > the HTML code around the selected text.
    >
    > But I can not now find it .... do you know where an example is?
    >
    > Many thanks
    > Mike.
    >
    >
    >[/color]

    Note: IE only
    Netscape/Mozilla have a way to get selected text, but it doesn't play
    nice with input elements like textareas. Opera has no way to write to
    the selection. No way found for other browsers.

    <html>
    <head>
    <title> Adding HTML tags to selected text - IE only</title>
    <script type="text/javascript" language="javas cript">
    function doTag(which)
    {
    // IE only - netscape's range object doesn't work well with textareas
    if (document.selec tion)
    {
    switch (which)
    {
    case "bold":
    s = document.select ion.createRange ().text;
    document.select ion.createRange ().text = "<b>"+s+"</b>";
    break;
    case "italic":
    s = document.select ion.createRange ().text;
    document.select ion.createRange ().text = "<i>"+s+"</i>";
    break;
    }
    }
    }
    </script>

    </head>

    <body>
    <form name="f1" action="" method="get" onSubmit="retur n false">
    <p>Work area: <textarea cols="50" rows="10" name="workarea"
    id="workarea"> </textarea></p>
    <p>
    <input type="button" name="b_bold" id="b_bold" onClick="doTag( 'bold')"
    value="BOLD"> &nbsp;
    <input type="button" name="b_italic" id="b_italic" onClick="doTag
    ('italic')" value="ITALIC"> &nbsp;
    </p>
    </form>
    </body>
    </html>


    --
    --
    ~kaeli~
    Why did kamikaze pilots wear helmets?



    Comment

    • Mike Walker

      #3
      Re: Textbox + Javascript

      Thats great - and works well - many thanks

      also
      thanks to Simon Wigzell who sent me some advice.

      Regards
      Mike.


      "kaeli" <tiny_one@NOSPA M.comcast.net> wrote in message
      news:MPG.1a9a96 8617f07582989c2 1@nntp.lucent.c om...[color=blue]
      > In article <6mOXb.6193$vo1 .3313@newsfep4-winn.server.ntl i.net>, mike42
      > @ntlworld.com enlightened us with...[color=green]
      > > Hi,
      > > Please can you help me,
      > > I have seen some free JavaScript that has a text box, with buttons under[/color][/color]
      it[color=blue][color=green]
      > > Bold, Italic, Underline, so when the text in the box is highlighted, it[/color][/color]
      puts[color=blue][color=green]
      > > the HTML code around the selected text.
      > >
      > > But I can not now find it .... do you know where an example is?
      > >
      > > Many thanks
      > > Mike.
      > >
      > >
      > >[/color]
      >
      > Note: IE only
      > Netscape/Mozilla have a way to get selected text, but it doesn't play
      > nice with input elements like textareas. Opera has no way to write to
      > the selection. No way found for other browsers.
      >
      > <html>
      > <head>
      > <title> Adding HTML tags to selected text - IE only</title>
      > <script type="text/javascript" language="javas cript">
      > function doTag(which)
      > {
      > // IE only - netscape's range object doesn't work well with textareas
      > if (document.selec tion)
      > {
      > switch (which)
      > {
      > case "bold":
      > s = document.select ion.createRange ().text;
      > document.select ion.createRange ().text = "<b>"+s+"</b>";
      > break;
      > case "italic":
      > s = document.select ion.createRange ().text;
      > document.select ion.createRange ().text = "<i>"+s+"</i>";
      > break;
      > }
      > }
      > }
      > </script>
      >
      > </head>
      >
      > <body>
      > <form name="f1" action="" method="get" onSubmit="retur n false">
      > <p>Work area: <textarea cols="50" rows="10" name="workarea"
      > id="workarea"> </textarea></p>
      > <p>
      > <input type="button" name="b_bold" id="b_bold" onClick="doTag( 'bold')"
      > value="BOLD"> &nbsp;
      > <input type="button" name="b_italic" id="b_italic" onClick="doTag
      > ('italic')" value="ITALIC"> &nbsp;
      > </p>
      > </form>
      > </body>
      > </html>
      >
      >
      > --
      > --
      > ~kaeli~
      > Why did kamikaze pilots wear helmets?
      > http://www.ipwebdesign.net/wildAtHeart
      > http://www.ipwebdesign.net/kaelisSpace
      >[/color]


      Comment

      Working...