Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    18,310
    Thanks
    203
    Thanked 2,563 Times in 2,541 Posts

    Netscape 7.0 and focus()

    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();
    }
    }

  • #2
    Senior Coder joh6nn's Avatar
    Join Date
    Jun 2002
    Location
    72° W. 48' 57" , 41° N. 32' 04"
    Posts
    1,887
    Thanks
    0
    Thanked 1 Time in 1 Post
    is NS giving any errors when this happens? or it's just not doing anything?
    bluemood | devedge | devmo | MS Dev Library | WebMonkey | the Guide

    i am a loser geek, crazy with an evil streak,
    yes i do believe there is a violent thing inside of me.

  • #3
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    18,310
    Thanks
    203
    Thanked 2,563 Times in 2,541 Posts
    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.

  • #4
    Senior Coder
    Join Date
    Jun 2002
    Location
    Wichita
    Posts
    3,880
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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.
    Check out the Forum Search. It's the short path to getting great results from this forum.

  • #5
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    18,310
    Thanks
    203
    Thanked 2,563 Times in 2,541 Posts
    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.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •