4

How can I open a keyboard prompt without touch on textfield when page loads? I also need to set the cursor on to that field so that keyboard will auto open to type easily.

My Code is:

$("#email").focus();
$('#email').trigger('click');

This will works only in firefox browser not in chrome and others. Also in iphone cursor is not setting on that field.

Rory McCrossan
  • 331,213
  • 40
  • 305
  • 339
  • I think you can not do this. Check this: http://stackoverflow.com/questions/14362066/jquery-mobile-show-keyboard-on-input-focus or this http://stackoverflow.com/questions/6020400/showing-androids-soft-keyboard-when-a-field-is-focusd-using-javascript – vaso123 Apr 28 '15 at 10:31
  • I already try the code which u post in http://stackoverflow.com/questions/6020400/showing-androids-soft-keyboard-when-a-field-is-focusd-using-javascript but not open keyboard automatically in mobile also not focusing cursor on that text field in iphone mobile @ Lolka_bolka – IRSHAD SAHEB Apr 28 '15 at 11:20
  • If you read the answers, you will see, both of the responder sad, it can not be done. – vaso123 Apr 28 '15 at 11:26
  • Yeah i know but y that codes works in mozilla firefox browser only in mobile not in others...@ Lolka_bolka - – IRSHAD SAHEB Apr 28 '15 at 12:44
  • And if something works in firefox, then is that mean, it should work in all other browsers on all OS? I think, you just kidding. – vaso123 Apr 28 '15 at 13:22
  • ahhh...Y u not understanding this is my problem..I add that too line in my code ... When i check in mobile firefox browser it working good but not in other browser. In iphone 5 mobile the cursor not showing on textfield also not open keyboard to any browser... This Problem am facing...@ Lolka_bolka – IRSHAD SAHEB Apr 28 '15 at 13:37
  • Yes, I understanding your problem. What I try to say to you, you want to do something, what is can not be achieved in all browsers, and on all OS. Because, this feature, seems works only with firefox, it is not a crossbrowser compatible feature. So, this is why I suggest to you, forget it. It can not be done. – vaso123 Apr 28 '15 at 14:53

1 Answers1

0

Please note we have autofocus attribute in HTML5 which does this without any javascript code.

For example:

<input type="text" name="fname" autofocus/>

You can refer to: autofocus example

mynawaz
  • 1,599
  • 1
  • 9
  • 16