Thank-you so much! I spent the entire day yesterday on this. I figured that was a string issue, but just could not figure out how to convert the var into an integer. Works wonderfully!
Max
Main Topics
Browse All TopicsI want to add a number from a textbox, add it to today's date\time, and dsiplay the newdate\time (sometime in the future) in another textbox. My problem: the number from the textbox dosen't mathematically 'add' to the date - see examples below:
Textbox1 - name='adate' - this should display today's date/time with the value of Textbox2 added to it
Textbox2 - name='howmanydays', value=5
Using the textbox value of 5 above, if today's date is 11/2/2008, the new date (adate) SHOULD BE 11/7/2008, but what it does is 11/25/2008 - it just places the number after the exisiting day rather than adding to it.
Here is the code I am using:
function adddates2() {
var a_p = "";
var d = new Date();
var daysahead = window.document.frmcomm.ho
var interval = daysahead;
var futuredate = new Date(d.getYear(),d.getMont
var curr_date = futuredate.getDate();
var curr_month = futuredate.getMonth()+1;
var curr_year = futuredate.getFullYear();
var curr_hour = d.getHours();
if (curr_hour < 12)
{
a_p = "AM";
}
else
{
a_p = "PM";
}
if (curr_hour == 0)
{
curr_hour = 12;
}
if (curr_hour > 12)
{
curr_hour = curr_hour - 12;
}
if (d.getMinutes()<10)
{
var curr_min = '0' + d.getMinutes();
}
else
{
var curr_min = d.getMinutes();
}
if (window.document.frmcomm.h
{
window.document.frmcomm.ad
}
}
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
Business Accounts
Answer for Membership
by: GreenGhostPosted on 2008-12-03 at 10:34:51ID: 23088701
The problem is that the value from the textbox is a string. When you add it to the day, the day also gets converted to a string so that the data types match. The strings '2' and '5' gets concatenated into '25', which then gets converted to a number as the Date constructor only accepts numbers.
You just have to parse the value from the textbox into an integer:
Select allOpen in new window