With a little side of applesauce...

Tuesday, September 1, 2009

javascript - onChange and setting focus back to invalid entry

I was having trouble returning the cursor back to an input field after validating it during an onChange event, (as many have before). The following code works around this issue:

setTimeout(function () { obj.focus() }, 50); 

A jQuery example would be:
setTimeout( function () { $('#purchase_amount' + num).focus() }, 50 );

This answer comes in thanks to the author of the following posting:


No comments: