Javascript: How To Set Cursor to Textbox End
In order to set up a cursor to the end of the text box there are 2 choices:
- Use createTextRange method.
- Focus the field and then set value. <--
"The trick is to set the value of the element after setting the cursor. The cursor will then be moved with it as the new value is written and end up at the end..."
< html> < head> < title>< /title> < script language="javascript"> function func() { var t2 = document.getElementById("t2"); t2.focus(); t2.value = t2.value; } < /script> < /head> < body> < input type="text" id="t1" value="aa"> < br /> < input type="text" id="t2" value="bb"> < br /> < input type="button" id="b" value="Run" onclick="func();" /> < /body> < /html>
Friday, January 5, 2007 1:14 AM