divesouth
12-10-2003, 07:21 AM
is there a simple script to make sure that the departure date is not before the arrival date ?
|
Click to See Complete Forum and Search --> : departure date to be after arrival date divesouth 12-10-2003, 07:21 AM is there a simple script to make sure that the departure date is not before the arrival date ? Pittimann 12-10-2003, 08:10 AM Hi! Yes there is - but whatfor :confused: :confused: :confused:... <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <title>Untitled</title> <script language="JavaScript" type="text/javascript"> <!-- function dateCheck() { var depDate = new Date("December 3, 2003"); var arrDate = new Date("December 2, 2003"); if (arrDate.getTime() <= depDate.getTime()) { alert('Departure: '+depDate+'\nArrival: '+arrDate+'\nOK - departure not before arrival'); } else { alert('Departure: '+depDate+'\nArrival: '+arrDate+'\nNot OK - departure before arrival'); } } //--> </script> </head> <body onload="dateCheck()"> </body> </html> Sorry for the little joke :D You didn't mean something like the opposite??? If so, just play with "<=", "<", ">=" or ">" in the line: if (arrDate.getTime() <= depDate.getTime()) { Cheers - Pit BTW: sometimes I wish I could arrive somewhere before I leave... divesouth 12-10-2003, 08:30 AM thanks, I'll have a look at your code to see if it works better than the one i've found in the meantime.. have a look at my example here: http://www.kwamnandi.co.za/drafts/forms/datepicker/form.html - it works with mm/dd/yyyy this one works up to a certain degree... it works if the dates are all for one year, but the moment you span two years it does what it is supposed to do, except works off the mm/dd first...anyway, i'll look at your code Your joke is fine....good to know there is someone out there with a sense of homour :D BTW: don't we all wish the same - arriving before departure !! Pittimann 12-10-2003, 09:25 AM Hi! I've checked your code. Apart from the joke thing (you really check, wether departure is AFTER arrival) and the way, your script calculates, the code is ok. Something like this would help: <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <title>Untitled</title> <script language="JavaScript" type="text/javascript"> <!-- function checkcalc(bookbed) { var depDate = new Date(bookbed.departureDate.value); var arrDate = new Date(bookbed.arrivalDate.value); if (bookbed.arrivalDate.value==0 || bookbed.departureDate.value==0){ alert("Please choose dates for both departue and arrival."); return false; } else if (arrDate.getTime() <= depDate.getTime()) { alert("The arrival date should be after the departure date. Please Check."); return false; } else return (true); } //--> </script> </head> <body> <form name=bookbed onsubmit="return checkcalc(this)"> <table cellpadding=2 cellspacing=0 border=0> <tr> <td>dep: <input name="departureDate" type=text value="" maxlength=10 size=15 onFocus="this.blur()" style="font-size: xx-small;"></td> <td><a href="javascript:void( window.open( 'calendar.html?departureDate', '', 'width=200,height=210,top=120,left=120' ))"><img src='calendar.gif' border=0></a> Select</td> </tr> <tr> <td>arr: <input name="arrivalDate" type=text value="" maxlength=10 size=15 onFocus="this.blur()" style="font-size: xx-small;"></td> <td><a href="javascript:void( window.open( 'calendar.html?arrivalDate', '', 'width=200,height=210,top=120,left=120' ))"><img src='calendar.gif' border=0></a> Select</td> </tr> </table> <input type="submit" name="B1" value="Confirm" style="font-size: xx-small;"> </form> </body> </html> I am sure, your stuff isn't meant for dates in the past, anyway, please note: Your date picker returns only a yy value for the year instead of yyyy. So - if you select a departure date in the 90ies and an arrival date in - let's say - 2001 you turn out to have a Year2k problem. If - apart from Year2k, you want to display a yyyy value for the year, just eliminate the following line from your calender file: function getYear( year ) { retval = new String( year ); retval = retval.slice( 2, 4 ); return retval; } Cheers - Pit divesouth 12-11-2003, 12:58 AM I tried removing: function getYear( year ) { retval = new String( year ); retval = retval.slice( 2, 4 ); return retval; } it only results in the calendar page not loading, so i looked again and saw i only had to remove retval = retval.slice( 2, 4 ); not he whole function. I works now :) Thanks Pit Pittimann 12-11-2003, 01:01 AM Hi! Sorry!! Only the red line... Cheers - Pit divesouth 12-11-2003, 01:04 AM thanks, i saw that too late thanks for your help... much appreciated webdeveloper.com
Copyright Internet.com Inc., All Rights Reserved. |