Autoclosing on screen keyboard after clicking return on mobile devices
Hello visitors!
Today i was developing a standard ajax form for a mobile web app and i noticed that the nasty on screen keyboard doesn’t close after pressing the “return” button and it still send the request.
So the deal is “how to close the ipad (or whatsoever) keyboard after pressing the device button” while knowing that web pages could rarely affect the device behavior?
The solution is so simple that i find it embarrassing… you noticed that if you click the submit button the keyboard close itself?
Then why not simulating that click, the focus to be specific. Yeah that’s all.
I expect you already have a javascript ajax call setup, probably jquery, since this situation only occurs when not changing page:
$('#submit').click(function(e) {
e.preventDefault();
$.ajax(....);
});
then simply add this line:
$('#submit').focus();
focusing on the submit button, or what you used to trigger the call. Result:
$('#submit').click(function(e) {
e.preventDefault();
$('#submit').focus();
$.ajax(....);
});
That’s all!
No comments yet.