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

10-16-2005, 11:19 PM

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">
<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");
return false;
if (passForm.passwd1.value != passForm.passwd2.value) {
alert("Entered passwords did not match");
return false;
return true;

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

Thanks for any tips and comments in advance.


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

10-17-2005, 01: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.


EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum