astralaaron Posted November 20, 2008 Share Posted November 20, 2008 Hi this works in firefox, but is not compatible with IE... I searched around and saw people saying that the selectionStart and selectionEnd is not IE supported... does anyone have a solution for this in IE ? <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head> <title>Selection Test</title> <script type="text/javascript"> function insrtTxt(){ var x = document.aform.btxt; var y = "[b]enter bold text[/b]"; x.focus(); x.value += y; var k = x.value.length; x.selectionStart = k - 19; x.selectionEnd = k - 4; } </script> </head> <body> <a href="java script: insrtTxt();">bold</a> <form name="aform"> <textarea name="btxt" cols="40"></textarea> </form> </body> </html> Link to comment Share on other sites More sharing options...
rnd me Posted November 20, 2008 Share Posted November 20, 2008 i use the following code to do this in IE.it's labeled close to the firefox properties.you will have to add a branch for IE that uses "obj.selectionStart2()" instead of "obj.selectionStart" TXT.selectionStart2 = function(){ var n=Math.abs(document.selection.createRange().moveStart("character", -1000000)); return n; }; TXT.selectionEnd2 = function(){ var dcr = document.selection.createRange(); var n=Math.abs(dcr.moveStart("character", -1000000)); return n + dcr.text.length; } hope this helpsEDIT: hmm, this is read only, so it probably won't help you...i'll leave it up for others. Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.