English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
All categories

How do you stop a form in javascript from submitting if the information does not match. One example being a password and a password confirm not matching. How would you stop it from submitting?

2007-12-07 07:25:15 · 3 answers · asked by mathew s 1 in Computers & Internet Programming & Design

3 answers

Generally, I prefer not to use a "submit" button. I create a button to call a validation routine, and, if the form elements pass all of the validation requirements, then the function calls the submit() method on the form; otherwise, some error handling is invoked.









Enter password:
type="password"
id="p1" />



Verify password:
type="password"
id="p2" />



type="button"
value="click to submit password"
onclick="validate();" />



2007-12-07 09:13:49 · answer #1 · answered by richarduie 6 · 0 0

Use the "return false" command.
For example:

onsubmit="return password(formName)">







2007-12-07 15:30:20 · answer #2 · answered by ♦♦Phil♦♦ 3 · 1 0

Here's a dhtml form validation example:

http://www.dhtmlgoodies.com/index.html?whichScript=dhtml-form-validation

2007-12-07 15:31:45 · answer #3 · answered by daa 7 · 0 0

fedest.com, questions and answers