Focus OnLoad = "document.form_id.form_field_id.focus ();" on iPhone

Is there a way to focus on the text field while loading the page (on iphone)?

I did my best:

OnLoad="document.form_id.form_field_id.focus();" 

on the iPhone Simulator, but that didn't work.

Does anyone know why this does not work and if so, is there a workaround?

+3
source share
2 answers

Try

OnLoad="document.getElementById('form_field_id').focus()"
0
source

It is better to use standard methods of access to forms and forms of management:

document.forms.form_id.elements.form_field_id.focus();

(notice formand elementsaddition).

or

document.forms['form_id'].elements['form_field_id'].focus();

if identifiers / form / form names have characters that cannot be part of Javascript identifiers, for example. "|", "-", "." etc.

( ), , , .

, . , Safari ? ?

window.setTimeout(function(){
  document.forms['form_id'].elements['form_field_id'].focus();
}, 100);
0

Source: https://habr.com/ru/post/1704557/


All Articles