Is there a way to focus on a text field on page load (on the iphone)? I tried:
OnLoad="document.form_id.form_field_id.focus();" on the iPhone Simulator but it didnt work.
Does anybody now why this doesnt work and if so is there a work around?
Is there a way to focus on a text field on page load (on the iphone)? I tried:
OnLoad="document.form_id.form_field_id.focus();" on the iPhone Simulator but it didnt work.
Does anybody now why this doesnt work and if so is there a work around?
It's better to use standard ways to access forms and form controls:
document.forms.form_id.elements.form_field_id.focus();
(notice form
and elements
addition).
or:
document.forms['form_id'].elements['form_field_id'].focus();
if form/form control ids/names have characters that can't be part of Javascript identifiers, e.g. "|", "-", ".", etc.
Short notation (as in your example), even though widely supported, is not really standardized, and it's usually better to stick to standard practices.
I'm not sure what the problem is here. Perhaps mobile Safari doesn't support programmatic focus setting? Have you tried invoking focus with a slight delay?
window.setTimeout(function(){
document.forms['form_id'].elements['form_field_id'].focus();
}, 100);