PDA

View Full Version : Having trouble with 'onsubmit' function, can someone help me troubleshoot please?



davenet
10-17-2005, 12:19 AM
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.



<!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

scrypter
10-17-2005, 01:40 AM
missing the function closing curly bracket }.
Works ok for me on Firefox. Did you get a JS error?
Paul

davenet
10-17-2005, 02:12 AM
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