muscle
11-25-2003, 05:35 PM
I have a form in which a user selects two dates from a select box, firstMon and secondMon. Basically I'm running a server side check like so in coldfusion to verify the second date is not before the first date like so....
<cfif form.firstMon GT form.secondMon>
<script>
alert('Please select a proper date.');
document.location.href = 'search.cfm';
</script>
<cfelse>
I'd prefer to do this before the user even proceeds to the process page. Is this possible?
Here is an example, with no form action etc. basically on submit or even after the user selects the second date, I'd like to pop up some kind of alert if the first date is after the second date.
http://www.orlando-fitness.com/date.cfm
jaysolomon
11-25-2003, 07:18 PM
Maybe this will help you
<html>
<head>
<title></title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<script type="text/javascript">
<!--
function val(fObj){
var sel1 = fObj["firstMon"].options[fObj["firstMon"].selectedIndex].text;
var sel2 = fObj["secondMon"].options[fObj["secondMon"].selectedIndex].text;
if(new Date(sel2)< new Date(sel1)){
alert("Date is before the firstMon")
return false;
} else {
return true;
}
}
// -->
</script>
</head>
<body>
<form name="form1" method="post" action="" onsubmit="return val(this);">
<select name="firstMon">
<script language="JavaScript">
<!--
var m = new Date("Jun 04, 2001")
m.setHours(5);
var d = new Date();
var dow= d.getDay();
d = new Date(((dow==0)?-6:1-dow)*86400000+d.valueOf())
var td = (d.getMonth()+1)+"/"+d.getDate()+"/"+d.getFullYear()
for (i=0;i<152;i++)
{ var s = (m.getMonth()+1)+"/"+m.getDate()+"/"+m.getFullYear();
document.writeln("<option "+((td==s)?"selected ":"")+"value='"+s+"'>"+s+"</option>");
m = new Date( m.valueOf()+604800000);
}
//-->
</script>
</select>
<select name="secondMon">
<script language="JavaScript">
<!--
var m = new Date("Jun 04, 2001")
m.setHours(5);
var d = new Date();
var dow= d.getDay();
d = new Date(((dow==0)?-6:1-dow)*86400000+d.valueOf())
var td = (d.getMonth()+1)+"/"+d.getDate()+"/"+d.getFullYear()
for (i=0;i<152;i++)
{ var s = (m.getMonth()+1)+"/"+m.getDate()+"/"+m.getFullYear();
document.writeln("<option "+((td==s)?"selected ":"")+"value='"+s+"'>"+s+"</option>");
m = new Date( m.valueOf()+604800000);
}
//-->
</script>
</select>
<input type="submit" name="Submit" value="Submit">
</form>
</body>
</html>
muscle
11-25-2003, 07:43 PM
Excellent!! Thanks a million!
jaysolomon
11-25-2003, 08:04 PM
Glad to have helped.
Good Luck
jAy
Vincent Puglia
11-25-2003, 08:53 PM
Hi muscle,
Excellent!! Thanks a million!
Gee...a million what?? cups of :coffee: ?? :D
Hi jay & welcome to the City that fixes all problems eventually -- even yours. Glad to see you managed to post :D
Vinny
jaysolomon
11-25-2003, 09:04 PM
Hi Vinny
Thanks for the warm welcome :D
COBOLdinosaur
11-26-2003, 12:05 AM
Hmm.... more familar faces all the time. When does Michel show up? :rolleyes:
Vincent Puglia
11-26-2003, 12:07 AM
Hi Cobol :D
I'm betting on fritz the blank. Gee, you think my posting this url all over the place is bringing people in?
:D
Vinny
COBOLdinosaur
11-26-2003, 12:38 AM
Wherever I go the expert world follows. ;)
vBulletin® v3.6.4, Copyright ©2000-2008, Jelsoft Enterprises Ltd.