Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Javascript > Textbox + Javascript

Reply
Thread Tools

Textbox + Javascript

 
 
Mike Walker
Guest
Posts: n/a
 
      02-15-2004
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.


 
Reply With Quote
 
 
 
 
kaeli
Guest
Posts: n/a
 
      02-16-2004
In article <6mOXb.6193$(E-Mail Removed)>, 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

 
Reply With Quote
 
 
 
 
Mike Walker
Guest
Posts: n/a
 
      02-16-2004
Thats great - and works well - many thanks

also
thanks to Simon Wigzell who sent me some advice.

Regards
Mike.


"kaeli" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> In article <6mOXb.6193$(E-Mail Removed)>, 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
>



 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Rich TextBox / HTML TextBox Jay ASP .Net 5 04-28-2005 11:15 PM
Calendar popup - using ASP textbox instead of HTML textbox =?Utf-8?B?Q2hyaXM=?= ASP .Net 3 03-30-2005 06:02 PM
runat="server"....a simple html textbox or a webform server textbox...that is the question. Hazzard ASP .Net 2 07-23-2003 07:32 AM
Re: runat="server"....a simple html textbox or a webform server textbox...that is the question. Natty Gur ASP .Net 0 07-22-2003 03:57 AM
Re: VERY STRANGE BUG? Adding a textbox control causes other textbox control to fail??? S. Justin Gengo ASP .Net 0 07-16-2003 06:51 PM



Advertisments