Solved

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

Posted on 2012-08-28
2
653 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

OverviewThis article demonstrates a simple search form using AJAX. The purpose of the article is to demonstrate how to use the same code to render a page and javascript (JQuery) and AJAX to make subsequent calls to refine the results. The princip…
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 …
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…

863 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

22 Experts available now in Live!

Get 1:1 Help Now