Philip M
06-02-2003, 07:03 PM
The following works perfectly in MSIE, Opera and Netscape 4.7.
That is, entering an invalid date triggers the alert and returns the focus to the textbox.
But in Netscape 7.0 the focus simply disappears and is not
returned to the textbox by - thedate.focus(). The rest of the function still works.
Any advice or ideas, please? This fault screws up other parts of my form as well.
function checkstartDate(thedate) {
var a,b,c,f,err = 0;
a = thedate.value;
if (a.length != 5) err=1;
b = a.substring(0, 2);
c = a.substring(2, 3);
f = a.substring(3, 5);
if (/\D/g.test(b)) err=1; //not a number
if (/\D/g.test(f)) err=1;
if (f>yynow) err=1; // start date beyond 2-digit current year
if (b<1 || b>12) err=1;
if (b>mmnow && f==yynow) err=1; // start date beyond current month of current year
if (f<yynow-4) err=1; // start date over 4 years ago
if (c != '/') err=1;
if (a==0 || a==00 || a=='') err=0;
if (err==1) {
alert ('That is not a valid date.\nPlease re-enter [MM/YY]. ');
document.forms[0].StartDate.value = "";
thedate.focus();
}
}
That is, entering an invalid date triggers the alert and returns the focus to the textbox.
But in Netscape 7.0 the focus simply disappears and is not
returned to the textbox by - thedate.focus(). The rest of the function still works.
Any advice or ideas, please? This fault screws up other parts of my form as well.
function checkstartDate(thedate) {
var a,b,c,f,err = 0;
a = thedate.value;
if (a.length != 5) err=1;
b = a.substring(0, 2);
c = a.substring(2, 3);
f = a.substring(3, 5);
if (/\D/g.test(b)) err=1; //not a number
if (/\D/g.test(f)) err=1;
if (f>yynow) err=1; // start date beyond 2-digit current year
if (b<1 || b>12) err=1;
if (b>mmnow && f==yynow) err=1; // start date beyond current month of current year
if (f<yynow-4) err=1; // start date over 4 years ago
if (c != '/') err=1;
if (a==0 || a==00 || a=='') err=0;
if (err==1) {
alert ('That is not a valid date.\nPlease re-enter [MM/YY]. ');
document.forms[0].StartDate.value = "";
thedate.focus();
}
}