i'm using javascript to validate the check in date and check out date...
i couldn't make the validation work... could anypne help me.. i'll be gratefull and appreciate for your help..
below is my code:
-----------------------------------------------------------------
<%@page import="java.util.*" errorPage="ErrorHandler3.jsp"%>
<SCRIPT TYPE ="text/javascript" LANGUAGE="javascript">
<!--
function validate(theForm){
var missing="";
var space =" ";
var CitySpace="";
var retval = true;
retval = checkdate(theForm.IYear.options[theForm.IYear.selectedIndex].value,theForm.IMonth.options[theForm.IMonth.selectedIndex].value, theForm.IDay.options[theForm.IDay.selectedIndex].value,theForm.OYear.options[theForm.OYear.selectedIndex].value, theForm.OMonth.options[theForm.OMonth.selectedIndex].value,theForm.ODay.options[theForm.ODay.selectedIndex].value)
if(retval == false)
{
missing += "Invalid Date format - Check In Date cannot later than Check Out Date\n";
}
if(missing != "")
{
alert("You missed the following field or some of the format :\n\n" + missing +
"\nPlease complete and resubmit.");
return false;
}
function checkdate(IYear, IMonth, IDay, OYear, OMonth, ODay)
{
var imonth, Inmonth, omonth, Outmonth;
var iday, Inday, oday, Outday;
var arrmonthNo = new Array(13);
var arrmonthChar = new Array(13);
arrmonthChar[1] = '01';
arrmonthChar[2] = '02';
arrmonthChar[3] = '03';
arrmonthChar[4] = '04';
arrmonthChar[5] = '05';
arrmonthChar[6] = '06';
arrmonthChar[7] = '07';
arrmonthChar[8] = '08';
arrmonthChar[9] = '09';
arrmonthChar[10] = '10';
arrmonthChar[11] = '11';
arrmonthChar[12] = '12';
var arrdayNo = new Array(32);
var arrdayChar[1] = '01';
var arrdayChar[2] = '02';
var arrdayChar[3] = '03';
var arrdayChar[4] = '04';
var arrdayChar[5] = '05';
var arrdayChar[6] = '06';
var arrdayChar[7] = '07';
var arrdayChar[8] = '08';
var arrdayChar[9] = '09';
var arrdayChar[10] = '10';
var arrdayChar[11] = '11';
var arrdayChar[12] = '12';
var arrdayChar[13] = '13';
var arrdayChar[14] = '14';
var arrdayChar[15] = '15';
var arrdayChar[16] = '16';
var arrdayChar[17] = '17';
var arrdayChar[18] = '18';
var arrdayChar[19] = '19';
var arrdayChar[20] = '20';
var arrdayChar[21] = '21';
var arrdayChar[22] = '22';
var arrdayChar[23] = '23';
var arrdayChar[24] = '24';
var arrdayChar[25] = '25';
var arrdayChar[26] = '26';
var arrdayChar[27] = '27';
var arrdayChar[28] = '28';
var arrdayChar[29] = '29';
var arrdayChar[30] = '30';
var arrdayChar[31] = '31';
for (i = 1; i <= 12; i++)
{
arrmonthNo = i;
}
for (i = 1; i <= 12; i++)
{
if(IMonth == arrmonthChar)
{
imonth = arrmonthNo;
Inmonth = parseInt(imonth);
}
}
for (i = 1; i <= 12; i++)
{
if(OMonth == arrmonthChar)
{
omonth = arrmonthNo;
Outmonth = parseInt(omonth);
}
}
for (i = 1; i <= 31; i++)
{
arrdayNo = i;
}
for (i = 1; i <= 31; i++)
{
if(IDay == arrdayChar)
{
iday = arrdayNo;
Inday = parseInt(iday);
}
}
for (i = 1; i <= 31; i++)
{
if(ODay == arrdayChar)
{
oday = arrdayNo;
Outday = parseInt(oday);
}
}
if(parseInt(IYear) > parseInt(OYear))
{
return(false);
}
else if((Inmonth > Outmonth) & (parseInt(IYear) > parseInt(OYear))
{
return(false);
}
else if((Inday > Outday) & (Inmonth > Outmonth) & (parseInt(IYear) > parseInt(OYear))
{
return(false);
}
}//checkdate
}
----------------------------------------------------------------------
thanks for your help
regards,
yuetNiSwee
i couldn't make the validation work... could anypne help me.. i'll be gratefull and appreciate for your help..
below is my code:
-----------------------------------------------------------------
<%@page import="java.util.*" errorPage="ErrorHandler3.jsp"%>
<SCRIPT TYPE ="text/javascript" LANGUAGE="javascript">
<!--
function validate(theForm){
var missing="";
var space =" ";
var CitySpace="";
var retval = true;
retval = checkdate(theForm.IYear.options[theForm.IYear.selectedIndex].value,theForm.IMonth.options[theForm.IMonth.selectedIndex].value, theForm.IDay.options[theForm.IDay.selectedIndex].value,theForm.OYear.options[theForm.OYear.selectedIndex].value, theForm.OMonth.options[theForm.OMonth.selectedIndex].value,theForm.ODay.options[theForm.ODay.selectedIndex].value)
if(retval == false)
{
missing += "Invalid Date format - Check In Date cannot later than Check Out Date\n";
}
if(missing != "")
{
alert("You missed the following field or some of the format :\n\n" + missing +
"\nPlease complete and resubmit.");
return false;
}
function checkdate(IYear, IMonth, IDay, OYear, OMonth, ODay)
{
var imonth, Inmonth, omonth, Outmonth;
var iday, Inday, oday, Outday;
var arrmonthNo = new Array(13);
var arrmonthChar = new Array(13);
arrmonthChar[1] = '01';
arrmonthChar[2] = '02';
arrmonthChar[3] = '03';
arrmonthChar[4] = '04';
arrmonthChar[5] = '05';
arrmonthChar[6] = '06';
arrmonthChar[7] = '07';
arrmonthChar[8] = '08';
arrmonthChar[9] = '09';
arrmonthChar[10] = '10';
arrmonthChar[11] = '11';
arrmonthChar[12] = '12';
var arrdayNo = new Array(32);
var arrdayChar[1] = '01';
var arrdayChar[2] = '02';
var arrdayChar[3] = '03';
var arrdayChar[4] = '04';
var arrdayChar[5] = '05';
var arrdayChar[6] = '06';
var arrdayChar[7] = '07';
var arrdayChar[8] = '08';
var arrdayChar[9] = '09';
var arrdayChar[10] = '10';
var arrdayChar[11] = '11';
var arrdayChar[12] = '12';
var arrdayChar[13] = '13';
var arrdayChar[14] = '14';
var arrdayChar[15] = '15';
var arrdayChar[16] = '16';
var arrdayChar[17] = '17';
var arrdayChar[18] = '18';
var arrdayChar[19] = '19';
var arrdayChar[20] = '20';
var arrdayChar[21] = '21';
var arrdayChar[22] = '22';
var arrdayChar[23] = '23';
var arrdayChar[24] = '24';
var arrdayChar[25] = '25';
var arrdayChar[26] = '26';
var arrdayChar[27] = '27';
var arrdayChar[28] = '28';
var arrdayChar[29] = '29';
var arrdayChar[30] = '30';
var arrdayChar[31] = '31';
for (i = 1; i <= 12; i++)
{
arrmonthNo = i;
}
for (i = 1; i <= 12; i++)
{
if(IMonth == arrmonthChar)
{
imonth = arrmonthNo;
Inmonth = parseInt(imonth);
}
}
for (i = 1; i <= 12; i++)
{
if(OMonth == arrmonthChar)
{
omonth = arrmonthNo;
Outmonth = parseInt(omonth);
}
}
for (i = 1; i <= 31; i++)
{
arrdayNo = i;
}
for (i = 1; i <= 31; i++)
{
if(IDay == arrdayChar)
{
iday = arrdayNo;
Inday = parseInt(iday);
}
}
for (i = 1; i <= 31; i++)
{
if(ODay == arrdayChar)
{
oday = arrdayNo;
Outday = parseInt(oday);
}
}
if(parseInt(IYear) > parseInt(OYear))
{
return(false);
}
else if((Inmonth > Outmonth) & (parseInt(IYear) > parseInt(OYear))
{
return(false);
}
else if((Inday > Outday) & (Inmonth > Outmonth) & (parseInt(IYear) > parseInt(OYear))
{
return(false);
}
}//checkdate
}
----------------------------------------------------------------------
thanks for your help
regards,
yuetNiSwee