Don't understand why this isn't working. I have a simple 'input type="date"' field as such....
<input type="date" name="Date"/>
And I'm trying to set the value to todays date whenever the page loads with this function...
function setDate(date){
z=$(date).attr('value');
var today = new Date();
var dd = today.getDate();
var mm = today.getMonth()+1; //January is 0!
var yyyy = today.getFullYear();
if(dd<10){dd='0'+dd}
if(mm<10){mm='0'+mm}
today = yyyy+'-'+mm+'-'+dd;
$(date).attr('value',today);
}
I've done the normal debugging and I know this function is being called and I know that the variable 'today' does in fact hold todays date in the form 'yyyy-mm-dd'. I have tried doing all different types of date formats (dd/mm/yyyy, dd-mm-yyyy, etc.)
Any idea why this isn't working?
Users can type a date value into the text field of an input[type=date] with the date format shown in the box as gray text. This format is obtained from the operating system's setting. Web authors have no way to change the date format because there currently is no standards to specify the format.
datepicker. formatDate("dd-mm-yy", new Date())); Add the above code at the end of the script.
For input just use .val()
To read the value
z=$(date).val();
To set the value
$(date).val(today);
$('input[name=Date]').val(today);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With