XHTML, CSS, Javascript, Browser Notes

Monday, May 29, 2006

Focus Problem Javascript bug

For some reason, if I call the focus() function while using the 'this' object, it doesn't work. The workaround for this is to call the focus with a setTimeout(). For example:

I have this input field:
<input name="myField" value="stuff" onchange="doStuff(this)" />

Now, if I try to set the focus inside of doStuff, it simply does not work:
function doStuff(theInput)
{
theInput.focus();
}

?????
The workaround I am forced to use is to set a global var for theInput which I call inside of a setTimeout():

var theInputGlobal;
function doStuff(theInput)
{
theInputGlobal = theInput;
setTimeout('theInputGlobal.focus()',100);
}

Has anyone seen this before? Or have a better solution?

0 Comments:

Post a Comment

<< Home