Results 1 to 6 of 6

Thread: Netscape and javascript

  1. #1

    Thread Starter
    Addicted Member wernerh's Avatar
    Join Date
    Sep 2000
    Posts
    170

    Netscape and javascript

    Why doesnt this work when brosing with Netscape 6:
    Nothing happens, the validation never executes!

    <script ID=clientEventHandlersJS LANGUAGE=javascript>
    <!--
    function form1_onsubmit() {
    //Check that NO fields are BLANK
    if (form1.UserID.value == ""){
    window.alert ("Username must be entered!");
    form1.UserID.value = "";
    form1.UserID.focus();
    return false;
    }
    if (form1.password.value == ""){
    window.alert ("Password must be entered!");
    form1.password.focus();
    return false;
    }

    }
    //-->
    </script>

  2. #2
    Frenzied Member Mark Sreeves's Avatar
    Join Date
    Nov 1999
    Location
    UK
    Posts
    1,845
    I wasn't aware you could do that sort of event handler on netscape
    Mark
    -------------------

  3. #3
    Hyperactive Member progressive's Avatar
    Join Date
    Sep 2001
    Location
    Manchester, UK
    Posts
    404
    type javascript: in the location bar to find out what error is
    occuring. Then post what you get

  4. #4
    Hyperactive Member progressive's Avatar
    Join Date
    Sep 2001
    Location
    Manchester, UK
    Posts
    404
    ahah, on reflection you need to do this!

    Code:
    <html>
    <head>
    <script>
    function validateInput() //Check that NO fields are BLANK 
    {
    
      if (form1.UserID.value == "")
      { 
        window.alert ("Username must be entered!"); 
        form1.UserID.value = "";
        form1.UserID.focus(); 
        //return false; 
      } 
      else if (form1.password.value == "")
      { 
         window.alert ("Password must be entered!"); 
         form1.password.focus(); 
         //return false; 
      }
      else
      {
         document.form1.submit(); //all is well lets submit our form
      }
    
    }
    </script>
    </head>
    <body>
      <form name="form1" method="get" action="your.cgi" onsubmit="false; validateInput()">
        <input type="text" name="UserID">
        <input type="text" name="password">
        <input type="submit" value="submit">
      </form>
    </body>
    </html>
    haven't checked that code but am confident that it the solution you are aiming for
    Last edited by progressive; May 30th, 2002 at 08:36 AM.

  5. #5
    Frenzied Member
    Join Date
    Feb 2001
    Posts
    1,140
    1) Use vBulletin code tags.
    2) Netscape should have a debugger in it.
    3) You haven't set form1 to a value, so I don't expect it to work. If you want to call apon the form named form1 in your document, then use document.forms[0], document.forms["form1"], document.getElementsByName("form1")[0], et al. And as always, RTFM.
    Travis, Kung Foo Journeyman
    As always, RTFM.

    WWW Standards: HTML 4.01, CSS Level 2, ECMA 262 Bindings to DOM Level 1, JavaScript 1.3 Guide and Reference
    Perl: Learn Perl, Llama, Camel, Cookbook, Perl Monks, Perl Mongers, O'Reilly's Perl.com, ActiveState, CPAN, TPJ, and use Perl;
    YBMS, but Mozilla doesn't.

  6. #6
    Hyperactive Member progressive's Avatar
    Join Date
    Sep 2001
    Location
    Manchester, UK
    Posts
    404
    Inaccuracies in that last post of mine here is a functional version !

    Code:
    <html>
    <head>
    <script language="javascript">
    function validateInput(my_form) //Check that NO fields are BLANK
    {
    
      if (my_form.UserID.value == "")
      {
        window.alert ("Username must be entered!");
        my_form.UserID.value = "";
        my_form.UserID.focus();
        return false;
      }
      else if (my_form.password.value == "")
      {
         window.alert ("Password must be entered!");
         my_form.password.focus();
         return false;
    
      }
      else
      {
        //all is well lets submit our form
        return true;
      }
    
    }
    </script>
    </head>
    <body>
      <form name="form1" method="get" action="your.cgi" onSubmit="return validateInput(document.form1)">
        <input type="text" name="UserID">
        <input type="text" name="password">
        <input type="submit" value="submit">
      </form>
    </body>
    </html>

Posting Permissions

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



Click Here to Expand Forum to Full Width