javascript - Onclick current date and time in datetime-local input -
i trying current date , time on datetime-local input field, using onclick method.
i have tried using moment.js , other libraries this, reason, cannot translate current datetime-local field. doing wrong?
i decided go basics jquery alone , manged far.
if change input type text on input box, script works fine, if changed datetime-local, doesn't work.
$( function(){ $('#time').click(function(){ var time = new date(); $('#time-holder').val(time.todatestring()); }); } ); jsfiddle: jfiddle
when use input type datetime-local.
the date format must as: 'yyyy-mm-ddthh:mm:ss'
e.g: "2014-11-16t15:25:33"
$( function(){ $('#time').click(function(){ var time = moment().format('yyyy-mm-ddthh:mm:ss'); $('#time-holder').val(time); }); } ); solution here:
Comments
Post a Comment