mdaguerre
mdaguerre

Reputation: 1267

Problem with .focus() in web for iPhone

I´m having a problem with the jQuery .focus() function on a web page for iPhone. I have four inputs, when one input reach the maximun of 4 characters the focus have to move to the next input. This is the code.

<input type="password" name="cc_number_1" id="cc_number_1" onkeyup="checkCC1()" maxlength="4">
<input type="password" name="cc_number_2" id="cc_number_2" maxlength="4">


function checkCC1()
{
   if($('#cc_number_1').val().length == 4)
   {
      $('#cc_number_2').focus();
   }
}

The problem is that $('#cc_number_2').focus() is not working, the focus doesn´t move to the next input.

What i´m doing wrong??

Thanks!!

Upvotes: 1

Views: 1143

Answers (2)

Lennon
Lennon

Reputation: 111

That problem was probably caused because mobile safari doesn't support the "onKeyUp" event, have you tried "onKeyPress" ? The focus() part could be ok if the event is the cause... IDK

Upvotes: 1

Jeff B
Jeff B

Reputation: 30099

** Original answer removed as it did not solve the problem **

There is supposedly a documented bug on mobile Safari (in fact the webkit engine, so it affects other mobile browsers) that makes the keyboard disappear when the focus changes. This seems to be what I am seeing when I test. I am currently looking to see if there is a workaround.

Upvotes: 2

Related Questions