473,473 Members | 1,757 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Inserting today's date using JavaScript

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!
Nov 19 '05 #1
2 2036
getMonth() is zero based, so you need to add one to it.

-- bruce (sqlwork.com)
"Richard" <Ri*****@discussions.microsoft.com> wrote in message
news:95**********************************@microsof t.com...
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!

Nov 19 '05 #2
Thanks Bruce! That did it!

"Bruce Barker" wrote:
getMonth() is zero based, so you need to add one to it.

-- bruce (sqlwork.com)
"Richard" <Ri*****@discussions.microsoft.com> wrote in message
news:95**********************************@microsof t.com...
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!


Nov 19 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
by: peashoe | last post by:
I have an asp page that uses a calendar.js (pop-up) file to add an exact date format in the text field (txtDDate). My problem is I need some javascript that sets an alert that does not allow them...
1
by: Ben | last post by:
Hi all, I'm trying to write inside a table cell from external javascript but am not successful. When I insert inside a form within <td...>, it works but does not work for normal table cell. My...
15
by: Khurram | last post by:
I have a problem while inserting time value in the datetime Field. I want to Insert only time value in this format (08:15:39) into the SQL Date time Field. I tried to many ways, I can extract...
4
by: Michele Simionato | last post by:
Look at this example: >>> import psycopg >>> psycopg.__version__ '1.1.19' >>> import datetime >>> today = datetime.datetime.today() >>> co = psycopg.connect('') >>> cu = co.cursor()
7
by: joeyej | last post by:
How do I compare today's date with this string (in my inc file) so that I can set an alert if date choice i.e. May 15, 2006 not at least greater than two days from current date? <option...
4
by: Kun | last post by:
i have a form which takes in inputs for a mysql query. one of the inputs is 'date'. normally, a user has to manually enter a date, but i am wondering if there is a way to create a button which...
6
by: fniles | last post by:
I am using VB.NET 2003 and SQL Server 2000. I have a table with a datetime column type. When inserting into the table for that column, I set it to Date.Now.ToString("T") , which is something like...
2
by: Luqman | last post by:
Hi, Any Idea how to Display Todays Date in DetailView Template Field while Inserting ? For example: When I click on New Button of DetailView Control, I need to display Today's Date in a...
1
by: cptuser | last post by:
Hi, I have a date field on a form. The date in the date field has to be after today's date and not in the past. It also has to be within 30 days from today's date. So if today is 13/04/2007, then...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.