Use js to get the focus at the end of the text box and the focus at the end of the js text box
function moveEnd(obj) {obj.focus();var len = obj.value.length;if (document.selection) {var sel = obj.createTextRange();sel.moveStart('character', len);sel.collapse();sel.select();} else if (typeof obj.selectionStart == 'number'&& typeof obj.selectionEnd == 'number') {obj.selectionStart = obj.selectionEnd = len;}}
How can I jump the cursor position to the end of the text box in JS to get the focus?
<Script language = "javascript">
Function setFocus ()
{
Var obj = event. srcElement;
Var txt = obj. createTextRange ();
Txt. moveStart ('character ', obj. value. length );
Txt. collapse (true );
Txt. select ();
}
</Script>
<Input type = "text" value = "abcdefg123456789" onfocus = "setFocus ()">
How can I jump the cursor position to the end of the text box after JS focus () is obtained?
<Input type = "text" id = "test1" name = "test1" value = "test123" onclick = "moveEnd (this);"/>
Function moveEnd (obj ){
Obj. focus ();
Var len = obj. value. length;
If (document. selection ){
Var sel = obj. createTextRange ();
Sel. moveStart ('character ', len );
Sel. collapse ();
Sel. select ();
} Else if (typeof obj. selectionStart = 'number'
& Typeof obj. selectionEnd = 'number '){
Obj. selectionStart = obj. selectionEnd = len;
}
}