Solved

Use JavaScript to auto populate a date field based on another date field

Posted on 2012-08-28
2
657 Views
Last Modified: 2012-08-29
Let's say a user opens a page with a form on it.  He clicks a box to add a date to a form field.  I want another form field to automatically populate with a date 10 days from the date that was just entered.  As a bonus, if it could automatically check if that new date fell on a Sat/Sun and if it did choose the date for the following Monday that would be very helpful. Thank you.
0
Comment
Question by:Jason92s
2 Comments
 
LVL 10

Accepted Solution

by:
tdlewis earned 500 total points
ID: 38343695
Here's a function that accepts a date string as input and returns a date string that is 10 days later (except weekends):
function laterDate(when)
{
  var d = new Date
  d.setTime(Date.parse(when) + 10 * 24 * 60 * 60 * 1000)
  if (d.getDay() == 6) d.setTime(d.getTime() + 24 * 60 * 60 * 1000)
  if (d.getDay() == 0) d.setTime(d.getTime() + 24 * 60 * 60 * 1000)
  var str = d.toLocaleDateString()
  return str
}

Open in new window

0
 

Author Closing Comment

by:Jason92s
ID: 38348178
Thank you.
0

Featured Post

Independent Software Vendors: 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

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…
Introduction HyperText Transfer Protocol (http://www.ietf.org/rfc/rfc2616.txt) or "HTTP" is the underpinning of internet communication.  As a teacher of web development I have heard many questions, mostly from my younger students who have come to t…
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…

749 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