View Full Version : Javascript date problem
StealthRT
Apr 26th 2006, 10:34 pm
Hey all i need to find a way to check to see if the user clicked on a date thats in the future (ie. a date thats pass todays date)
Code:
onClick="if(self.gfPop)gfPop.fPopCalendar(document.frmSurvey.dc);return false;"
The date is formatted like 04/14/2006
If today was the 14 and the user tryed to click any date after the 14th then i need it to blank out the frmSurvey.dc text box and tell them they can not select that date... or if thats hard then simply clear the text box.
Thanks for your help,
David
dexfantasy
Apr 27th 2006, 11:45 am
Not sure if this is the best way to do it, but I'd do something like
IF currentyear < selectedyear
or if currentyear == selectedyear and currentmonth < selectedmonth
or if currentyear == selectedyear and currentmonth == selectedmonth and currentday < selectedday
THEN
clear the textbox
So, in javascript, it might look something like this
var datestring = "04/27/2008";
var d = new Date();
var cd = [d.getMonth() + 1, d.getDate(), d.getFullYear()]; // current date
var sd = datestring.split('/'); // selected date
if ( cd[2] < sd[2] || cd[2] == sd[2] && cd[0] < sd[0] || cd[2] == sd[2] && cd[0] == sd[0] && cd[1] < sd[1] )
document.frm.dc.value = "";
StealthRT
Apr 28th 2006, 5:54 pm
Where would i put that code with the code i already have?
David
StealthRT
Apr 28th 2006, 6:39 pm
Here is the .html file that it used to show the calender and stuff...
David
dexfantasy
Apr 28th 2006, 8:58 pm
a. the code you are working with is copyrighted
b. the code you gave me relies on code you didn't give me
c. i don't get the sense that you are putting in much an effort to solve this yourself. I'm new here, so I don't mean to be presumptuous, but I'm guessing you will have better luck at a site like rentacoder.com.
Dex
StealthRT
Apr 28th 2006, 9:37 pm
Then consider this topic deleted....
vBulletin® v3.8.4, Copyright ©2000-2009, Jelsoft Enterprises Ltd.