1

I am using this line of code:

  document.getElementById("myfield").focus()

in JavaScript, to bring the focus to a given text input field.

On a computer (I am using a Mac) it works fine, but on a mobile (iPhone, iPad) it does not work.

I did the experiment both with Firefox and Safari, the result is the same.

Does anyone know why and how to make it work?

Michel
  • 10,303
  • 17
  • 82
  • 179
  • Possible duplicate of [Mobile Safari: Javascript focus() method on inputfield only works with click?](https://stackoverflow.com/questions/12204571/mobile-safari-javascript-focus-method-on-inputfield-only-works-with-click) – Zenoo Jul 31 '18 at 10:11
  • Use .click() instead... Here is the nice reference https://stackoverflow.com/questions/12204571/mobile-safari-javascript-focus-method-on-inputfield-only-works-with-click – Ullas Hunka Jul 31 '18 at 10:11
  • It seems that ios focus doesn't work => https://stackoverflow.com/questions/5978470/ipad-html-focus – Fabien Greard Jul 31 '18 at 10:13
  • @UllasHunka You should really learn [how to handle duplicate questions.](https://meta.stackexchange.com/questions/10841/how-should-duplicate-questions-be-handled) – Zenoo Jul 31 '18 at 10:13

0 Answers0