?
Solved

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

Posted on 2012-08-28
2
Medium Priority
?
671 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
[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 Comments
 
LVL 10

Accepted Solution

by:
tdlewis earned 2000 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

On Demand Webinar: Networking for the Cloud Era

Ready to improve network connectivity? Watch this webinar to learn how SD-WANs and a one-click instant connect tool can boost provisions, deployment, and management of your cloud connection.

Question has a verified solution.

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

JavaScript can be used in a browser to change parts of a webpage dynamically. It begins with the following pattern: If condition W is true, do thing X to target Y after event Z. Below are some tips and tricks to help you get started with JavaScript …
In this blog, we’ll look at how improvements to Percona XtraDB Cluster improved IST performance.
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

765 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