Solved

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

Posted on 2012-08-28
2
649 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
Comment Utility
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
Comment Utility
Thank you.
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

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…

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

12 Experts available now in Live!

Get 1:1 Help Now