Setting the value of date inputs on iPad

15,950

Solution 1

Try this for Safari on iOS 5

 $('input[type="date"]').val('yyyy-MM-dd');

You could do the conversion from the type of Date you are using to yyyy-MM-DD in JavaScript using the Date() function.

Solution 2

for iOS6 the ISO format "YYYY-MM-DDTHH:mm:ss.sssZ" is required:

var now = new Date().toISOString();
$("input[type=datetime]").val(now);
Share:
15,950
Fresheyeball
Author by

Fresheyeball

Principled user interface person, professional Haskell engineer, verification/usability driven developer, and proponent of the directed acyclic graph.

Updated on July 03, 2022

Comments

  • Fresheyeball
    Fresheyeball almost 2 years

    WEB APP not native, no Objective-C

    This is so simple it hurts.

      <input type="date" />
    

    Done to use the iPad native datepicker. Then setting the initial value with jQuery

      $('input[type="date"]').val('Jun 25, 2012');
    

    Resulting in an empty input field. The jQuery above works great in ie7-9, chrome, safari, and FF, but not in iOS!

    I am out of ideas. Does anyone know a work around? Or why this happens?

  • Fresheyeball
    Fresheyeball almost 12 years
    what if that is not the date format I am looking for. Also, why?
  • Anirudh Ramanathan
    Anirudh Ramanathan almost 12 years
    I think the other formats don't work reliably. So I'd suggest you do the conversion in JavaScript using the Date() function. Since iOS5, there are other inputs as well. Detailed at shareourideas.com/2011/10/29/ios-5-and-html5-input-types
  • Fresheyeball
    Fresheyeball almost 12 years
    Holy bloody F#$#$. I tried this and the ipad accepted the input change, AND REFORMATTED IT ITSELF!
  • JeffAtStepUp
    JeffAtStepUp over 11 years
    Using new Date().toISOString().slice(0,10) on iOS here.
  • Sam
    Sam over 8 years
    You are my hero. This solution works in an ionic application for those that need to know.
  • Stubbs
    Stubbs over 8 years
    I was using attr to no avail, but val works great.