Solved

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

Posted on 2011-02-23
3
397 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 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

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!

Question has a verified solution.

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

This article will give core knowledge of JavaScript and will head in to your first JavaScript program. I am Durvesh Naik and I am here to deal with this series of JavaScript. I will teach you JavaScript in part wise , as its quite boring to read big…
Boost your ability to deliver ambitious and competitive web apps by choosing the right JavaScript framework to best suit your project’s needs.
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…
Suggested Courses

623 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