I am trying to return focus to a form input field.
If i use <form>.<field>.focus() the focus returns to the field but if
the field already contains a value it selects it (blacks it out).
Is it possible to focus on a input field but rather than selecting any
already inputted text, putting the cursor to the end of the field.
Cheers
> I am trying to return focus to a form input field.
> If i use <form>.<field>.focus() the focus returns
[quoted text clipped - 4 lines]
> than selecting any already inputted text, putting
> the cursor to the end of the field.
This should do the trick:
<form>
<input type="text" name="t" value="123">
<input type="button" value="click" onClick="
document.forms[0].t.focus()
var V = document.forms[0].t.value
document.forms[0].t.value = ''
document.forms[0].t.value = V
var L = (document.forms[0].t.value).length
if (document.forms[0].t.setSelectionRange) {
document.forms[0].t.setSelectionRange(L, L)
}
else if (document.forms[0].t.createTextRange) {
var range = document.forms[0].t.createTextRange()
range.collapse(true)
range.moveEnd('character', L)
range.moveStart('character', L)
range.select();
}
">
</form>
Hope this helps,
--
Bart