Solved

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

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

Simplifying Server Workload Migrations

This use case outlines the migration challenges that organizations face and how the Acronis AnyData Engine supports physical-to-physical (P2P), physical-to-virtual (P2V), virtual to physical (V2P), and cross-virtual (V2V) migration scenarios to address these challenges.

Question has a verified solution.

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

Suggested Solutions

Article by: DanRollins
This article describes a JavaScript program that creates a maze made of hexagonal cells.  In Part 2 (http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/A_7850-Hex-Maze-Part-2.html), we'll extend the program by adding a depth-…
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…

832 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