Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Show virtual keyboard on mobile phones in javascript

I'm creating a mobile version of my site. There's a part of the site where a dialog pops up with a text input. Normally I would just use jQuery to bring focus to the text input, but that's not working. Here's what I'm trying:

$("#textinput").focus(); $("#textinput").click();  $("#textinput").trigger("tap"); //jQuery Mobile 

None of them seem to work. Any ideas? I've been testing it on my DroidX. I'm using jQuery Mobile but I'm open to other libraries if they help.

like image 692
Adam Avatar asked Jul 26 '11 22:07

Adam


1 Answers

You can't, at least not in iOS (iPhone), and I believe Android as well. It's a usability issue that the keyboard should not be allowed to be triggered except by user input (it's just annoying if it's automatic).

There are a couple of ways I know of to get around this:

  • prompt() opens the keyboard
  • If you trigger the .focus() from within a .click() event (e.g. from opening your dialog), the keyboard shows up
like image 65
Nobody Avatar answered Sep 18 '22 21:09

Nobody