Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Set textbox focus in mobile safari

Hey, I was wondering how to set the focus to a text box in Mobile Safari.

I've tried document.myForm.myTextArea.focus() which works in regular Safari, but it does not seem to work in Mobile Safari.

To clarify, I want to set focus to a text box as soon as the user loads a page, and have the iPhone keyboard pop up.

like image 787
Morgan Avatar asked Mar 07 '10 23:03

Morgan


2 Answers

Just found this previous post stating this is a bug in webkit. Sorry for not doing a more thorough search.

http://discussion.forum.nokia.com/forum/showthread.php?t=127724

like image 82
Morgan Avatar answered Nov 15 '22 14:11

Morgan


I found a bug report with the iUI project relating to this.

It seems that a focus() call will not work if called from the onload event or if called via a timer.

http://code.google.com/p/iui/issues/detail?id=129

Update: Although I have no source for this, I am told (by people who have tried it) that in iPhone OS 4 the problem with focus() and onload should be fixed.

like image 27
cdmckay Avatar answered Nov 15 '22 15:11

cdmckay