chump2877
07-06-2006, 03:30 PM
I've been playing around with this code for a while now, and I just can;t seem to figure out a way to get this code to work in Mozilla/Firefox....
It seems that Mozilla's getSelection() method can only return a variable string value, and can;t actually attach a value to the current form object like IE's document.selection.createRange() can....
Anyway, it's giving me aheadache, and I can;t find any useful resources on the web to help me...If anyone can give me some tips or direct me towards an online tutorial for this, I would be immensely in your debt!
Here's my code so far (it only works in IE at the moment):
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html lang=en>
<head>
<title>Add System</title>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=ISO-8859-1">
<script type="text/javascript">
<!--
var isSelected = false;
var text;
function copySelection(workArea)
{
if (document.selection && document.selection.createRange)
{
workArea.workText = document.selection.createRange();
}
else if (document.getSelection)
{
text = document.getSelection();
}
isSelected = true;
}
function wrapInTags(workArea,isTag)
{
if (isSelected)
{
if (document.selection && document.selection.createRange)
{
workArea.workText.text = "["+isTag+"]"+workArea.workText.text+"[/"+isTag+"]";
if (workArea.workText.text==''){isSelected=false;workArea.focus()}
}
else if (document.getSelection)
{
workArea.value = "["+isTag+"]"+text+"[/"+isTag+"]";
}
}
}
-->
</script>
</head>
<body>
<form name="main">
<input name="bold" type="button" value="Bold" onclick="wrapInTags(window.document.main.area1,'b'); return false;">
<input name="italic" type="button" value="Italic" onclick="wrapInTags(window.document.main.area1,'i'); return false;">
<input name="underline" type="button" value="Underline" onclick="wrapInTags(window.document.main.area1,'u'); return false;">
<p><textarea name="area1" cols="53" rows="6" onselect="copySelection(window.document.main.area1)"></textarea></p>
</form>
</body>
</html>
It seems that Mozilla's getSelection() method can only return a variable string value, and can;t actually attach a value to the current form object like IE's document.selection.createRange() can....
Anyway, it's giving me aheadache, and I can;t find any useful resources on the web to help me...If anyone can give me some tips or direct me towards an online tutorial for this, I would be immensely in your debt!
Here's my code so far (it only works in IE at the moment):
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html lang=en>
<head>
<title>Add System</title>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=ISO-8859-1">
<script type="text/javascript">
<!--
var isSelected = false;
var text;
function copySelection(workArea)
{
if (document.selection && document.selection.createRange)
{
workArea.workText = document.selection.createRange();
}
else if (document.getSelection)
{
text = document.getSelection();
}
isSelected = true;
}
function wrapInTags(workArea,isTag)
{
if (isSelected)
{
if (document.selection && document.selection.createRange)
{
workArea.workText.text = "["+isTag+"]"+workArea.workText.text+"[/"+isTag+"]";
if (workArea.workText.text==''){isSelected=false;workArea.focus()}
}
else if (document.getSelection)
{
workArea.value = "["+isTag+"]"+text+"[/"+isTag+"]";
}
}
}
-->
</script>
</head>
<body>
<form name="main">
<input name="bold" type="button" value="Bold" onclick="wrapInTags(window.document.main.area1,'b'); return false;">
<input name="italic" type="button" value="Italic" onclick="wrapInTags(window.document.main.area1,'i'); return false;">
<input name="underline" type="button" value="Underline" onclick="wrapInTags(window.document.main.area1,'u'); return false;">
<p><textarea name="area1" cols="53" rows="6" onselect="copySelection(window.document.main.area1)"></textarea></p>
</form>
</body>
</html>