<> wrote in message
news: oups.com...
> Hello,
>
> I have an input element with an onfocus event handler that is
> responsible for changing its value:
>
> ---
> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
> <html>
> <head>
> <title></title>
> <script>
> function doSomething(objSender)
> {
> objSender.value = 'abc';
> }
> </script>
> </head>
> <body>
> <INPUT id="input1" type="text"><br>
> <INPUT id="input2" type="text"
> onfocus="doSomething(this);"><br>
> <INPUT id="input3" type="text">
> </body>
> </html>
> ---
>
> The problem is:
>
> I am in input1 and press the TAB key to navigate to input2. At this
> moment, if input2 is empty, it will change for 'abc' and will receive
> the focus (the cursor will be there). So far so good.
>
> However, if input2 is not empty, after pressing the TAB key, input2
> will change for 'abc' and WILL NOT RECEIVE THE FOCUS!
>
> Why this behavior? How can I have the focus set in input2, no matter
> if
> it's empty or not?
>
> I appreciate any help.
>
> Leonardo D'Ippolito
function doSomething(objSender)
{
objSender.value = 'abc';
if (objSender.createTextRange)
{
// added functionality, places the cursor at the
// end of any text in the input in IE or any other
// user agent that supports createTextRange(),
// TextRange#moveStart() and TextRange#select()
var r = objSender.createTextRange();
if (r.moveStart)
{
r.moveStart('character', objSender.value.length);
if (r.select)
{
r.select();
}
}
}
// fixes your initial problem, guarantees the input you
// just set the value of retains focus; may not be
// necessary - testing without seems to place focus
// on input by default with above code
objSender.focus();
}
--
Grant Wagner <>
comp.lang.javascript FAQ -
http://jibbering.com/faq