...

View Full Version : Netscape 7.0 and focus()



Philip M
06-02-2003, 08: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();
}
}

joh6nn
06-03-2003, 10:27 AM
is NS giving any errors when this happens? or it's just not doing anything?

Philip M
06-03-2003, 07:20 PM
Thanks for your response, joh6nn.

The script works, i.e. entering an invalid date causes the alert, and resets the textbox to "" (blank), but the focus appears to simply disappear. It can be brought back by clicking in the box, but the idea is to force re-entry of an invalid date.

As I say, it works fine in Netscape 4.7 so I am surprised that something is wrong here in NS7.

The same occurs in several other textboxes which call onblur(checksomething) which ends up with this.focus() if the validation fails.

Roy Sinclair
06-03-2003, 08:09 PM
Well it's not a valid script as shown, you don't define "yynow" within the script so you need to post the "setup" and it would also be a good idea to post the way you call the function but before you do either you might want to make sure you're handling the event properly by making sure you "return true" after calling the function, NS6 is more picky about event handling than IE.

Philip M
06-03-2003, 08:55 PM
Hello, Roy.

yynow is a global variable defined outside the function. You can guess that is the current year (03).

The script is called simply by

onblur="checkstartDate(this)"

Adding else{return true} does not make any difference.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum