Textbox + Javascript

Discussion in 'Javascript' started by Mike Walker, Feb 15, 2004.

  1. Mike Walker

    Mike Walker Guest

    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.
     
    Mike Walker, Feb 15, 2004
    #1
    1. Advertising

  2. Mike Walker

    kaeli Guest

    In article <6mOXb.6193$>, mike42
    @ntlworld.com enlightened us with...
    > 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.
    >
    >
    >


    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="javascript">
    function doTag(which)
    {
    // IE only - netscape's range object doesn't work well with textareas
    if (document.selection)
    {
    switch (which)
    {
    case "bold":
    s = document.selection.createRange().text;
    document.selection.createRange().text = "<b>"+s+"</b>";
    break;
    case "italic":
    s = document.selection.createRange().text;
    document.selection.createRange().text = "<i>"+s+"</i>";
    break;
    }
    }
    }
    </script>

    </head>

    <body>
    <form name="f1" action="" method="get" onSubmit="return 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
     
    kaeli, Feb 16, 2004
    #2
    1. Advertising

  3. Mike Walker

    Mike Walker Guest

    Thats great - and works well - many thanks

    also
    thanks to Simon Wigzell who sent me some advice.

    Regards
    Mike.


    "kaeli" <> wrote in message
    news:...
    > In article <6mOXb.6193$>, mike42
    > @ntlworld.com enlightened us with...
    > > 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.
    > >
    > >
    > >

    >
    > 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="javascript">
    > function doTag(which)
    > {
    > // IE only - netscape's range object doesn't work well with textareas
    > if (document.selection)
    > {
    > switch (which)
    > {
    > case "bold":
    > s = document.selection.createRange().text;
    > document.selection.createRange().text = "<b>"+s+"</b>";
    > break;
    > case "italic":
    > s = document.selection.createRange().text;
    > document.selection.createRange().text = "<i>"+s+"</i>";
    > break;
    > }
    > }
    > }
    > </script>
    >
    > </head>
    >
    > <body>
    > <form name="f1" action="" method="get" onSubmit="return 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
    >
     
    Mike Walker, Feb 16, 2004
    #3
    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. S. Justin Gengo
    Replies:
    0
    Views:
    536
    S. Justin Gengo
    Jul 16, 2003
  2. Hazzard
    Replies:
    2
    Views:
    551
    Yan-Hong Huang[MSFT]
    Jul 23, 2003
  3. Natty Gur
    Replies:
    0
    Views:
    462
    Natty Gur
    Jul 22, 2003
  4. =?Utf-8?B?Q2hyaXM=?=
    Replies:
    3
    Views:
    13,783
    Peter Blum
    Mar 30, 2005
  5. Jay

    Rich TextBox / HTML TextBox

    Jay, Apr 28, 2005, in forum: ASP .Net
    Replies:
    5
    Views:
    15,698
    Steve C. Orr [MVP, MCSD]
    Apr 29, 2005
Loading...

Share This Page