While <input type="date"> is not common for desktop, this is the preferred method for mobile.
I'm trying to implement the fallback code at the bottom of this section: http://diveintohtml5.info/forms.html#type-date
<form>
<input type="date">
</form>
<script>
var i = document.createElement("input");
i.setAttribute("type", "date");
if (i.type == "text") {
// No native date picker support :(
// Use Dojo/jQueryUI/YUI/Closure to create one,
// then dynamically replace that <input> element.
var script = document.createElement('script');
script.scr = "http://ajax.googleapis.com/ajax/libs/jqueryui/1.10.2/jquery-ui.min.js";
document.getElementsByTagName('head')[0].appendChild(script);
var style = document.createElement('style');
style.href = "http://code.jquery.com/ui/1.10.2/themes/smoothness/jquery-ui.css";
document.getElementsByTagName('head')[0].appendChild(style);
$(function() {
$.datepicker.setDefaults(
$.extend($.datepicker.regional['']);
);
});
}
</script>
Using the above logic, anything within $(function()) throws a console error and datepicker is undefinied. How do I rewrite this so that jQueryUI script and style only shows up when native datepicker isn't available?
I'm trying to keep http requests down and overall page performance faster on these pages for mobile browsers and Chrome since they all have native datepickers available.