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:

http://jsfiddle.net/alvarojoao/4hehnepw/


Comments

Popular posts from this blog

sublimetext3 - what keyboard shortcut is to comment/uncomment for this script tag in sublime -

java - No use of nillable="0" in SOAP Webservice -

ubuntu - Laravel 5.2 quickstart guide gives Not Found Error -