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:

http://www.nabble.com/Re%3A-set-focus-on-change-p15275386s27240.html

No comments: