Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 399
  • Last Modified:

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

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
ssailer
Asked:
ssailer
  • 2
1 Solution
 
ProculopsisCommented:

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
 
ssailerAuthor Commented:
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
 
ssailerAuthor Commented:
I was able to modify the solution to make it work for me.
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now