views:

777

answers:

2

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.

+2  A: 

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

Morgan
A: 

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.

cdmckay
Doesn't seem to be the case in iOS 4... Can others confirm?
Chris Lloyd
As in, focus() works in iOS 4?
cdmckay
Yes, the problem persists in iOS 4.
gregsabo