I am trying to have a specific form field focus automatically in the Safari browser on the iPhone. I thought it would be pretty straightforward, but I canβt get it to work. So, is this really impossible, or am I missing something super-obvious (which I suspect)? Here is the code I'm using:
<!DOCTYPE html> <html> <head> <script type="text/javascript"> function formfocus() { document.getElementById('element').focus(); } window.onload = formfocus; </script> </head> <body> <form> <input/> <input id="element" autofocus/> <input/> </form> </body> </html>
You can see that I am trying to get focus twice, once through js and once using the HTML attribute "aufofocus" in the input field. And the trick too. This works on desktop browsers, but when I open the page on my iPhone 4, there are no cubes, that is, I have to set the focus manually by clicking on one of the form fields.
Ultimately, I would like to open the website in a mobile browser and focus on the form field, including the keyboard open to start typing.
Thanks for any help!
javascript html5 iphone mobile-safari focus
pixelphantom Apr 24 '11 at 16:35 2011-04-24 16:35
source share