View Full Version : Manipulating Caret/Cursor position in textboxes

10-01-2003, 12:52 AM
I need help manipulating the caret/cursor position in a textbox. It's actually for a 'virtual keyboard' that updates textbox content. The function will add text wherever the current position is (i.e., after hitting <, >, Home, End, etc), but I can't display the caret in that location.

Suppose I've typed "TEST" with the virtual keyboard. The following function easily displays the caret at the end of the text, but trying to change the position leads to problems:

function showCursor(field,len) {
//Display caret/cursor at current position.
if (document.myForm[field].createTextRange) {
var r = document.myForm[field].createTextRange();
r.moveStart('character', len);

(*note 'len' refers to the current position.)
This only keeps the caret at the end of the textbox string, and doesn't allow the keyboard function to update the position (ie, <, >). Any ideas? Thanks!