Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

form validation function

Status
Not open for further replies.

Dashley

Programmer
Dec 5, 2002
925
US
I have a JS validation function that works just fine.
I want to modify it so it validates on the form submit
(which it does) but only when the submit button value is "commit" and not "save". So I added to the function:

&& (document.form1.submitButton == 'commit' )

Well now it dosen't alert when the save button is clicked
which is a good thing but it won't validate when the commit button is clicked.


The input for the commit is :
<INPUT type="submit" Value="commit" name="commit">

Code:
function validate_form()	{
    if (( document.form1.cpd3.checked == false )&& ( document.form1.cpd4.checked == false ) && ( document.form1.cpd5.checked == false ) && ( document.form1.cpd37.checked == false ) && (document.form1.submitButton == 'commit' ))
    {
        alert ( "Please check one of the Quality checkboxes." );
        valid = false;
    }
)

The function above is a lot longer than the example but its redundant info so I ommited alot of it.

Thanks

Dan
 
IDMF


Well it was on the subnit but after reading everything ad trying it out I had a brainstorm - why not just put it on a click vent on te specific button rather than a form onsubmit.


It worked out well that way


-dan
 
If you call the validation from the submit button, the form will be submitted even if the validation returns false. That's why it was suggested that you put it in the form onsubmit event handler.

Lee
 
exactly trollacious, the only other was round is to not have any submit buttons, and in the onlcick function issue document.formname.submit(); if you want the form submitted.

"In complete darkness we are all the same, only our knowledge and wisdom separates us, don't let your eyes deceive you.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top