0

I have a form that I am using jQuery to submit via ajax and when I submit the form I want to close the keyboard on the iPhone that is submitting the form. Currently, I am using the following code for the form portion of it

<form method="POST" id="login">
    <input id="username" type="text" name="username" autocomplete="off">
    <input id="password" type="password" name=password" autocomplete="off">
    <input id="submit" type="submit" name="submit" value="Login">
</form>

And I am using this jQuery to close the keyboard on submit

$('input').keyup(function(event) {
    if (event.which === 13) {
      $(this).blur();
    }
});

$('#login').submit(function(e) {
    e.preventDefault();
    $('input').blur();
    .....
});

When the user submits the form by pressing the SUBMIT button on the page, it closes the keyboard properly. But on my testing devices, iPhone 5s on iOS 11 and iPhone 7 on newest iOS, the form opens the keyboard with a GO button on the bottom of it, which when pressed submits the form the same way as the pressing submit does, but it doesn't close the keyboard even though it's been blurred out.

Is there something I am missing here to make this form close the keyboard on the phone properly?

Kaboom
  • 674
  • 6
  • 27
  • Possible duplicate of [can't blur input in ios](https://stackoverflow.com/questions/45487878/cant-blur-input-in-ios) – Sabbin Mar 22 '18 at 08:27
  • It blurs on submit when pushing the button, this solution does not work. Pushing GO on the keyboard, which should replicate the enter key and triggers the login event, does NOT close the keyboard. – Kaboom Mar 23 '18 at 07:08

0 Answers0