Hello all,
I was making a bbcode powered posting system for my new site when I came along a problem. I have been working with Nile (well he's doing most of the coding, I'm just kind of a feedback system) and his code works perfectly for Firefox, but alas, IE is very glitchy. Here is the code:
Nile says that "the problem is probably with selectionStart and selectionEnd", but in any case Firefox works fine, IE well, does not. If you selected "quick" from "The quick brown dog" the output its:Code:function bbSelected(myField, myValue){ var obj = document.getElementById(myField); var s = obj.selectionStart; var e = obj.selectionEnd; var start = obj.value.slice(0, obj.selectionStart); var end = obj.value.slice(obj.selectionEnd, obj.value.length); var middle = obj.value.substring(obj.selectionStart, obj.selectionEnd); var text = start + '['+myValue+']' + middle + '[/'+myValue+']' + end; var text = start + '['+myValue+']' + middle + '[/'+myValue+']' + end; document.getElementById(myField).value = text; document.getElementById(myField).focus(); if(document.getElementById(myField).setSelectionRange){ //not IE document.getElementById(myField).setSelectionRange(s+(myValue.length + 2), e+(myValue.length + 2)); } else if (document.getElementById(myField).createTextRange){ var range = document.getElementById(myField).createTextRange(); range.collapse(true); range.moveEnd('character', s+(myValue.length + 3)); range.moveStart('character', e+(myValue.length + 3)); range.select(); } }This is really bizarre. What is going on and how can I fix this?Code:the quick brown dog[form]the quick brown dog[/form]the quick brown dog



) and his code works perfectly for Firefox, but alas, IE is very glitchy. Here is the code:
Reply With Quote
Bookmarks