There is an error in the below mentioned code which is used to check for the date
i. e when the date is entered ....the js code written checks if its a valid date or not.
it works fine with netscape ..but gives an error icon on the status bar for IE.
function checkdate(date_a)
{
var err = 0;
a = date_a.value;
if (a.length != 10) err = 1;
b1 = a.substring(0,2); //date
var b=parseInt(b1);
c = a.substring(2,3); //'-'
d1 = a.substring(3,5); //month
var d=parseInt(d1);
e = a.substring(5,6); //'-'
f1 = a.substring(6,10); //year
f = parseInt(f1);
if (isNaN(f)) alert("INVALID YEAR FORMAT - Enter in yyyy format"
//basic error checking
if (b < 1 || b > 31) alert("INVALID DAY ! PL Enter Date between 01 and 31"
if (c != '-') alert("INVALID FORMAT ! Please enter a -(Hifen) after entering date"
if (d < 1 || d > 12) alert("INVALID MONTH ! PL Enter Month between 1 and 12"
if (e != '-') alert("INVALID FORMAT ! Please enter a -(Hifen) after entering month"
if (f < 1900 || f > 9999) alert("INVLAID YEAR ! PL Enter Year between 1900 and 9999"
//advanced error checking
//month with 30days
if (d == 4 || d == 6 || d == 9 || d ==11)
if (b >= 31)
alert("INVALID DAY ! Date entered must be within 31"
//month = feb & leap year
if (d == 2)
{
g = f/4;
if (b > 29) alert("Wrong input ! Date entered must be within 30"
if (b == 29)
if((f%100 == 0 || f%4 != 0) && (f%400 != 0))
alert("Wrong input ! A leap year cannot have the entered date"
}
}
i accept the date as below in a form named f1 & check it by onchange( )
<input type="text" size="11" maxlength="11" name="date" onchange="checkdate(document.f1.date);">
i. e when the date is entered ....the js code written checks if its a valid date or not.
it works fine with netscape ..but gives an error icon on the status bar for IE.
function checkdate(date_a)
{
var err = 0;
a = date_a.value;
if (a.length != 10) err = 1;
b1 = a.substring(0,2); //date
var b=parseInt(b1);
c = a.substring(2,3); //'-'
d1 = a.substring(3,5); //month
var d=parseInt(d1);
e = a.substring(5,6); //'-'
f1 = a.substring(6,10); //year
f = parseInt(f1);
if (isNaN(f)) alert("INVALID YEAR FORMAT - Enter in yyyy format"
//basic error checking
if (b < 1 || b > 31) alert("INVALID DAY ! PL Enter Date between 01 and 31"
if (c != '-') alert("INVALID FORMAT ! Please enter a -(Hifen) after entering date"
if (d < 1 || d > 12) alert("INVALID MONTH ! PL Enter Month between 1 and 12"
if (e != '-') alert("INVALID FORMAT ! Please enter a -(Hifen) after entering month"
if (f < 1900 || f > 9999) alert("INVLAID YEAR ! PL Enter Year between 1900 and 9999"
//advanced error checking
//month with 30days
if (d == 4 || d == 6 || d == 9 || d ==11)
if (b >= 31)
alert("INVALID DAY ! Date entered must be within 31"
//month = feb & leap year
if (d == 2)
{
g = f/4;
if (b > 29) alert("Wrong input ! Date entered must be within 30"
if (b == 29)
if((f%100 == 0 || f%4 != 0) && (f%400 != 0))
alert("Wrong input ! A leap year cannot have the entered date"
}
}
i accept the date as below in a form named f1 & check it by onchange( )
<input type="text" size="11" maxlength="11" name="date" onchange="checkdate(document.f1.date);">