13

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.

cdmckay
  • 31,832
  • 25
  • 83
  • 114
Morgan
  • 1,765
  • 2
  • 19
  • 26

3 Answers3

5

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
  • 1,765
  • 2
  • 19
  • 26
4

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
  • 31,832
  • 25
  • 83
  • 114
1

Nothing to do with the timer, focus() doesnt work at all... im doing mine through an AJAX function. i guess my web application will have to suffer in mobile safari.

Bye the way, this also affects HP webOS devices and any other device using mobile safari

Dante
  • 11
  • 1