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);
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, 2022Comments
-
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 almost 12 yearswhat if that is not the date format I am looking for. Also, why?
-
Anirudh Ramanathan almost 12 yearsI 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 almost 12 yearsHoly bloody F#$#$. I tried this and the ipad accepted the input change, AND REFORMATTED IT ITSELF!
-
JeffAtStepUp over 11 yearsUsing
new Date().toISOString().slice(0,10)
on iOS here. -
Sam over 8 yearsYou are my hero. This solution works in an ionic application for those that need to know.
-
Stubbs over 8 yearsI was using
attr
to no avail, butval
works great.