Hi all,
I am adding buttons to a text area for formatting the text. in firefox i'm losing the focus on the text area in IE7 its ok but at the end of the text. what i would like is for the focus to work in firefox and the cursor to be placed in between the tags. like you get when posting on this forum! all my closing tags are 4 characters long so I know i need to find the end of the text then minus 4 but not sure how to do this? or is there a better way of doing it?
Code so far:
Code JavaScript:function inserttag(myField, myValue) { //IE support if (document.selection) { myField.focus(); sel = document.selection.createRange(); sel.text = myValue; } //MOZILLA/NETSCAPE support else if (myField.selectionStart || myField.selectionStart == '0') { var startPos = myField.selectionStart; var endPos = myField.selectionEnd; myField.value = myField.value.substring(0, startPos) + myValue + myField.value.substring(endPos, myField.value.length); } else { myField.value += myValue; } }
Form:
HTML Code:<form id="form1" name="form1" method="post" action=""> <input type="button" name="bold" id="bold" value="Bold" onClick="inserttag(document.form1.arttext,'[B][EB]');" /> <input type="button" name="bold" id="bold" value="Italic" onClick="inserttag(document.form1.arttext,'[I][EI]');" /><br /> Article: <textarea name="arttext" id="arttext" cols="45" rows="5"></textarea> </form>




Bookmarks