1

So I have a Javascript form using a Date picker:

<input name="date" type="date" id="date"/>

I would like the input field to already be selected when the screen loads. Scenario: user on an iOS device loads this form, and the Date Picker automatically comes up, without them having to tap on the drop down element in the HTML.

Any ideas?

Thanks.

Jake Chasan
  • 6,290
  • 9
  • 44
  • 90

1 Answers1

0

You need to use the focus() method, then you can set the focus on your input on body load, as follow:

<input class=".dtInput" name="date" type="date" id="date"/>

<script type="text/javascript">
    $('body').onload(function(){
        $('.dtInput').focus();
    }
</script

Use the jquery to easily get the elements of you page

Claudio Santos
  • 1,307
  • 13
  • 22
  • 1
    -1 jquery isn't needed and this isn't jquery. `document.getElementById(el).focus();` – 1252748 Oct 25 '13 at 22:17
  • This does not seem to work on iOS Safari. Is there a tweak to this code which will allow it to work on iOS devices? – Jake Chasan Oct 26 '13 at 00:05
  • may this [link](http://stackoverflow.com/questions/18728166/programatically-focus-on-next-input-field-in-mobile-safari) could help you. – Claudio Santos Oct 26 '13 at 00:29