Solved

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

Posted on 2011-02-23
3
394 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
  • 2
3 Comments
 
LVL 20

Accepted Solution

by:
Proculopsis earned 250 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

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
HTTPS jquery doesn't work 9 63
javascript comparing two dates 3 19
Mobile page Scrolling down when refreshing 4 33
Jquery Validation Messages Not Showing Up 3 15
Article by: DanRollins
This article describes a JavaScript program that creates a maze made of hexagonal cells.  In Part 2 (http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/A_7850-Hex-Maze-Part-2.html), we'll extend the program by adding a depth-…
This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
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…

803 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