Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
153
rated 0 times [  157] [ 4]  / answers: 1 / hits: 61122  / 11 Years ago, sat, june 29, 2013, 12:00:00

Please see this fiddle: http://jsfiddle.net/yg49k/



The following code works fine in FireFox but doesn't work in the latest version of Chrome.



HTML:



<input type=text id=one placeholder=Type two chars />
<input type=text id=two placeholder=It should focus here />


jQuery:



$(#one).on(input, function() {
if($(#one).val().length == 2) { $(#two).focus(); }
});


Does anyone know how I can get around this?


More From » jquery

 Answers
31

Seems like a bug in Chrome. Sometimes it is too fast to execute events properly;)



Found a workaround http://jsfiddle.net/Rd2rZ/



$(#one).on(input, function() {
if($(#one).val().length == 2) {
setTimeout(function(){
$(#two).focus();
}, 1);
}
});


Use setTimeout with a minimal delay. It will slow down Chrome and make it work.


[#77304] Friday, June 28, 2013, 11 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
abagail

Total Points: 528
Total Questions: 109
Total Answers: 101

Location: Western Sahara
Member since Mon, May 3, 2021
3 Years ago
;