...

View Full Version : Manipulating Caret/Cursor position in textboxes



cstetson
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);
r.moveEnd('character',len);
r.collapse();
r.select();
}
}

(*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!



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum