Solved

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

Posted on 2011-02-23
3
347 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
Comment Utility

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

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

In my daily work (mainly using ASP.net), I need to write a lot of JavaScript code. One of the most repetitive tasks I do are the jQuery Ajax calls. You know: (CODE) I don't know if for you it's the same, but for me is soooo tedious to write the …
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
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…

771 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now