![]() |
Complete novice needs a steer with HTML input form using javascript
Can someone give me a steer in the right direction.
I have an HTML form that requires two dates to be entered. Date 1 containes the current date and date 2 is set to the current date + 1, 2, 3 or 4 years in the future less 1 day. Dates are UK format dd/mm/yyyy. This is done with a PHP script on the serverside. e.g. Date 1: 02/11/2012 Date 2: 01/11/2016 If the user changes date 1: to say 02/06/2012 I would like to set the second date to 01/06/2016. Can this be done in javascript. (You can probably guess I'm a complete novice when it comes to javascript Many thanks in advance) |
It can be done with JavaScript but as not everyone has JavaScript you'll still need to check for it on the server.
To get the date so many years in the future less your one day you could use: Code:
newDate = function(years) { |
felgall's script is fine to add x years to the current date, but if the date is derived from a date entered by the user into an input box things get more complicated. You need to check that the entered date is in the correct format, within a valid range, and is a valid date (not 56th Febtember).
Code:
<html>Do please read the posting guidelines regarding thread titles. The thread title is supposed to help people who have a similar problem in future. Yours is useless for this purpose. You can (and should) edit it to make it more meaningful. For example "Set a date x years ahead". "I know that you believe that you understand what you think I said, but, I am not sure you realise that what you heard is not what I meant". (Robert McCloskey) |
Quote:
Quote:
|
Quote:
"If the user changes date 1: to say 02/06/2012 I would like to set the second date to 01/06/2016." |
So there were actually two completely different things being asked for. Anyway only a very minor modification to the code I originally supplied is needed to be able to start with any date at all.
Code:
Date.prototype.newDate = function(years) { |
Yes, but as I have said,
You need to check that the entered date is in the correct format, within a valid range, and is a valid date (not 56th Febtember). My script does that. |
| All times are GMT +1. The time now is 12:07 PM. |
Powered by vBulletin®
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.