Textbox + Javascript

M

Mike Walker

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.
 
K

kaeli

mike42 said:
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>


--
 
M

Mike Walker

Thats great - and works well - many thanks

also
thanks to Simon Wigzell who sent me some advice.

Regards
Mike.
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,535
Members
45,007
Latest member
obedient dusk

Latest Threads

Top