Inserting today's date using JavaScript

G

Guest

I have a textbox and an HtmlInputButton control on a Webform for an Intranet
app. When the user clicks the button, it is supposed to add today's date to
the textbox using JavaScript on the client side.

However, it is adding last month's date to the textbox, not today's date. I
checked the regional settings and date/time section of both the client
machine and the web server. Both are set correctly for CA and daylight
savings time, and both show the correct date/time on the Taskbar.

Here is the JavaScript I'm using that I found Googling:
function addDate(){
TheDate = new Date();
var theMonth = TheDate.getMonth();
var theDay = TheDate.getDate();
var theYear = TheDate.getFullYear();

if (document.getElementById('txtFollowUpNeeds').value == ''){
document.getElementById('txtFollowUpNeeds').value = theMonth + '/' + theDay
+ '/' + theYear + ': ';
}
else {
document.getElementById('txtFollowUpNeeds').value += '\r\n' + theMonth + '/'
+ theDay + '/' + theYear + ': ';
}
}

And here is the line in my Page_Load event:
btnAddDate.Attributes.Add("onClick", "addDate();")

Any ideas on how to make this work?

Thanks in advance!
 
B

Bruce Barker

getMonth() is zero based, so you need to add one to it.

-- bruce (sqlwork.com)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top