First of all sorry about my poor English, i´ll try to do the best.
Well, i´m having a similar problem because i wan´t to select certaint
characters from a text box. Maybe this routine i´ve just created , solves
your problem.
This routine, selects in a textbox characters from StartIndex to EndIndex.
If you gives to the routine both parameters with textbox content lenght, i
think it puts the cursor in the desired position.
function selectFromTo (textInput, charStartIndex, charEndIndex) {
/* We´ll calculate the appropiate value to the different moves. */
strTextInputValue = "" + textInput.value;
charStartIndex = (parseInt(charStartIndex) - 1);
numEndIndex = parseInt(charEndIndex);
numEndIndex -= strTextInputValue.length;
charEndIndex = numEndIndex.toString();
if (textInput.createTextRange) {
var range = textInput.createTextRange();
range.moveStart('character', charStartIndex );
range.moveEnd('character', charEndIndex);
range.select();
}
}
Raul Carrillo a.k.a Metsuke
"Christian" <cg********@yahoo.com> escribió en el mensaje
news:bo**********@reader1.imaginet.fr...
Hello,
As the subject says it, is there a way to simulate a special keypress in
JS ? In my case, on loading an HTML page, i'd like to set the cursor at the
end of the input text of an <input type=text ...> object.
focus() sets the cusor at the beginning
Any idea ?
Christian.