Expiring Today—Celebrate National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

javascript add ten days to a field and fill in another field with the new date

Posted on 2011-02-23
3
Medium Priority
?
398 Views
Last Modified: 2012-05-11
Can anyone tell me why this javascript isn't working and what I'm doing wrong?
<script type="text/javascript">  
<!--
function setNewDate() {  
var db = new document.WADAUpdateForm.DateBilled.value;
db.setDate(db.getDate()+10);
document.WADAUpdateForm.DueDate.value=((db.getMonth()+1)+"/"+db.getDate()+"/"+db.getFullYear());
}
//-->
</script>

These are my form fields:
<input name="DateBilled" id="DateBilled" value="<cfoutput>#LSDateFormat(WADAInvoices.DateBilled,'M/DD/YY')#</cfoutput>" size="15" onChange="setNewDate()" />
<input name="DueDate" id="DueDate" value="<cfoutput>#LSDateFormat(WADAInvoices.DueDate,'M/DD/YY')#</cfoutput>" size="15" />
When someone changes the date in the date billed field, I want the due date to automatically display a date 10 days from the new date billed.  I am not good with javascript, by the way.

Thank you!
0
Comment
Question by:ssailer
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 20

Accepted Solution

by:
Proculopsis earned 750 total points
ID: 34967869

Try something like this:

<html>
<head>
<title>http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/Q_26843174.html</title>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.5/jquery.min.js" type="text/javascript"></script>
<script src="http://filedb.experts-exchange.com/incoming/2011/02_w07/406422/DateExtension.js" type="text/javascript"></script>
<script>

$(document).ready(function() {

  $("#Calculate").click( calculateDueDate );

});

function calculateDueDate() {
  var billDate;
  var dueDate;

  billdate = Date.parse( $("#DateBilled").val() );
  if ( ! isNaN( billdate ) ) {
    dueDate = new Date( billdate );
    dueDate = new Date( dueDate.setDate( dueDate.getDate() + 10 ) );
    $("#DueDate").val( dueDate.toString( "MM/dd/YYYY" ) );
  }
}

</script>
</head>
<body>

<input name="DateBilled" id="DateBilled" value="" size="15" />
<input id="Calculate" type="button" value="+10"  />
<input name="DueDate" id="DueDate" value="" size="15" />

</body>
</html>

Open in new window

0
 

Author Comment

by:ssailer
ID: 34969986
I don't want to user to have to click a button to generate the new date, but I can probably modify this to make it work onChange.  Thanks!
0
 

Author Closing Comment

by:ssailer
ID: 35832608
I was able to modify the solution to make it work for me.
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The task A number given should be formatted for easy reading by separating digits into triads. Format must be made inline via JavaScript, i.e., frameworks / functions are not welcome. So let’s take a number like this “12345678.91¿ and format i…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

719 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question