Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Setting the value of date inputs on iPad

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?

like image 491
Fresheyeball Avatar asked Jun 25 '12 05:06

Fresheyeball


2 Answers

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.

like image 78
Anirudh Ramanathan Avatar answered Nov 15 '22 18:11

Anirudh Ramanathan


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

var now = new Date().toISOString();
$("input[type=datetime]").val(now);
like image 30
TaeKwonJoe Avatar answered Nov 15 '22 18:11

TaeKwonJoe