<!DOCTYPE html>
<
html
>
<
body
>
<
center
>
<
h1
>Put Cursor at End of Input</
h1
>
<
input
id
=
"idText"
type
=
"text"
size
=
"70"
value
=
"Cursor at the End"
>
<
button
onclick
=
"PosEnd(idText);"
>
Put Cursor at end of Text
</
button
>
</
center
>
<
script
>
/* Creating a function called PosEnd
in JavaScript to place the cursor
at the end */
function PosEnd(end) {
let len = end.value.length;
// Mostly for Web Browsers
if (end.setSelectionRange) {
end.focus();
end.setSelectionRange(len, len);
} else if (end.createTextRange) {
let t = end.createTextRange();
t.collapse(true);
t.moveEnd('character', len);
t.moveStart('character', len);
t.select();
}
}
</
script
>
</
body
>
</
html
>