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">
<input type="button" name="b_italic" id="b_italic" onClick="doTag
('italic')" value="ITALIC">
</p>
</form>
</body>
</html>
--