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 3 of 3
  1. #1
    New to the CF scene
    Join Date
    Oct 2005
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Having trouble with 'onsubmit' function, can someone help me troubleshoot please?

    Hello.

    I'm new to Javascript and I'm working through a sample problem in a book I'm using for a tutorial. I've gone through this script with a fine tooth comb, so to speak, and am unable to figure out the problem.

    I have uploaded the file to my web server and opened it in both Firefox and IE. When I click the submit button, the page tries to process the CGI script and completely ignores the Javascript.

    The script is supposed to validate that I have 2 passwords that are the same or to open an alert box with a message if I do not.

    I've included the code I'm working with below.

    Code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <title>Password Check</title>
    <script language="Javascript" type="text/javascript">
    	<!-- Hide script from older browsers
    	
    	function validForm(passForm) {
    		if (passForm.passwd1.value == "") {
    			alert("You must enter a password");
    			passForm.passwd1.focus();
    			return false;
    		}
    		if (passForm.passwd1.value != passForm.passwd2.value) {
    			alert("Entered passwords did not match");
    			passForm.passwd1.focus();
    			passForm.passwd1.select();
    			return false;
    		}
    		return true;
    	-->
    </script>
    </head>
    
    <body>
    <form onsubmit="return validForm(this)" action="someCGI.cgi">
    Your name: <input type="text" size="30" />
    <p>Choose a password: <input type="password" name="passwd1" /></p>
    <p>Verify password: <input type="password" name="passwd2" /></p>
    <p><input type="submit" value="Submit" />&nbsp;<input type="reset" /></p>
    </form>
    </body>
    </html>
    Thanks for any tips and comments in advance.

    David
    Last edited by davenet; 10-17-2005 at 12:32 AM.

  • #2
    New Coder
    Join Date
    Sep 2005
    Location
    New Zealand
    Posts
    27
    Thanks
    0
    Thanked 0 Times in 0 Posts
    missing the function closing curly bracket }.
    Works ok for me on Firefox. Did you get a JS error?
    Paul
    ScrypTik Javascript editor with built in syntax error checking

  • #3
    New to the CF scene
    Join Date
    Oct 2005
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Sometimes the easy stuff is the hardest to find. Thanks man.

    I did not get any errors in Firefox, it just ignored the script competely and tried to post to the CGI.

    David


  •  

    Posting Permissions

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