PDA

View Full Version : Resolved HTML tags not working in Firefox



james438
11-16-2009, 11:28 PM
Hi,

I am not fluent in javascript at all, but I have this relatively simple program that works in Opera and IE, but not Firefox. Anyone have an idea on how the script can be altered to work in Firefox?


<script type="text/javascript">
function insertAtCursor(myField, myValue) {
//IE support
if (document.selection) {
myField.focus();
sel = document.selection.createRange();
sel.text = myValue;
}
else
{
myField.value += myValue;
}</script>
<script type="text/javascript">
function saveCurRng() {
curRng = document.selection.createRange().duplicate();
}
function surround(btag, etag){
if (curRng) {
document.editform.article.focus();
curRng.text= btag + curRng.text + etag;
return false;
}
}
</script>
</head>
<body>
<form name="editform">
<textarea rows=5 cols=40 name="article" onKeyup="saveCurRng()" onMouseup="saveCurRng()"></textarea>
</form>
<a href="#" onclick="return surround('<b>', '</b>');">bold</a><br>
<a href="#" onclick="return surround('<i>', '</i>');">italic</a>

james438
11-17-2009, 03:50 AM
Sorry, I updated the script to remove the junk code.

james438
11-18-2009, 12:07 AM
The solution can be found in this thread (http://www.dynamicdrive.com/forums/showthread.php?t=50020&page=3).