0

I need a text input field to be ready to type into as soon as the page opens. I've found a couple of questions like this answered, but none of them seem to be specific to whether or not it's possible to do on an iPad.

I'm using this javascript:

window.onload = function(){
    var text_input = document.getElementById('barcode');
    text_input.focus ();
    text_input.select ();  
}  

and my HTML for the input is this:

<input type="text" name="text" class="textinput" id="barcode">

When I test the webpage in Google Chrome it works, but when I test it on my iPad it doesn't. I've also tried the HTML5 autofocus element, but I've heard that doesn't work on iPad either.

MadSkunk
  • 2,867
  • 2
  • 33
  • 45
Grooms
  • 25
  • 3

1 Answers1

0

I've had a similar issue in the past on an iPad.

You could try running your code on a button press and see if that works, if it does then it may be the same issue I had whereby the iPad wasn't allowing code that ran automatically to perform certain functions.

In my case I wanted to start an html 5 video tag playing, but could only do so on a button press and not automatically when the page loaded.

As other have suggested, try putting an alert() in your window.onload method, or try setting a timeout and running this code after a few milliseconds. If you can verify that your code is actually being run, that would be a start.

MadSkunk
  • 2,867
  • 2
  • 33
  • 45
  • After lots more research, I finally found this: [link](http://stackoverflow.com/questions/6287478/mobile-safari-autofocus-text-field). It turns out that IOS doesn't allow automatic focus as it would normally bring up the keyboard automatically, which would get annoying for users. – Grooms Mar 05 '13 at 17:55