Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I focus an HTML text field on an iPhone (causing the keyboard to come up)?

Tags:

I'm writing an iPhone web app, and I want to automatically focus a text field when the page is loaded, bringing up the keyboard. The usual Javascript:

input.focus(); 

doesn't seem to be working. Any ideas?

like image 685
Ross Avatar asked Jun 11 '09 04:06

Ross


People also ask

How can I focus on a text input without showing on screen keyboard?

1) use the onFocus event to immediately trigger the blur event to hide the keyboard again. 2) set readonly="true" on the element, later remove it and trigger the focus event.


1 Answers

It will only show the keyboard if you fire focus from a click event, so put a button on the page with a onclick that does the focus and it will show the keyboard. Completely useless except for validation (on click of submit validation code focuses on invalid element)

like image 78
BAM Avatar answered Sep 29 '22 23:09

BAM