Pre-Populated Date in Text Field

Posted by user2537332 on Stack Overflow See other posts from Stack Overflow or by user2537332
Published on 2013-06-30T22:12:15Z Indexed on 2013/06/30 22:21 UTC
Read the original article Hit count: 156

Filed under:
|
|

I am trying to pre-populate a text box with today's date, but for some reason, it keeps showing today's date as 5/30/13, which is a month behind. This code should just be pulling the local time so why is it a month behind? Here is my code, can someone please tell me why the current date is off...Please help, :)

var dateToday=new Date();

function loadDate(){
    var today=dateToday.getMonth() + "/"
    +dateToday.getDate()+"/"+dateToday.getFullYear();
    document.forms[0].curDate.value=today;
}

function orderReady(orderTime){
    dateToday.setDate(dateToday.getDate()+orderTime);
    var ready=dateToday.getMonth()+"/"
    +dateToday.getDate()+"/"+dateToday.getFullYear();
    document.forms[0].puDate.value=ready;
}

<body onload="loadDate();">

<p>Today's Date<br />
<input type="text" name="curDate" size="50" /><br />

© Stack Overflow or respective owner

Related posts about JavaScript

Related posts about html