Help with JS validation in an html form

digitalarts

New member
Aug 24, 2009
45
0
0
I hv a form where I hv 2 submit buttons (the one we discussed, where putting emp ID populates employee name etc)

One submit button does the work of populating the employee details when I enter Emp ID and click on it.

The other submit button submits the form data to DB when I fill up the form and click on submit.

Now before the form data is submitted, I want to validate whether each field is correctly filled so I am uisng Java script for this.
And I am uisng this statement to validate.

<form action= "form.php" method="post" enctype="multipart/form-data" name="myform" id="myform" onsubmit="return (formCheck(this) && validateit(this.Hr_ticket.value));">

With the above code, even if I click on the submit button that populates the employee details, it shows up the Java script validation. I only want the JS validation for the submit button that actually puts the form data into DB.
 


1) Stop texting (i.e. "hv" instead of "have", "DB" instead of "Database") when you are typing on a forum.

It's incredibly annoying having to spend extra time inferring what you mean. It's a major pet peeve of mine. You have a keyboard, use it. It takes only a couple more seconds of your time and saves a lot of time for the people reading what you are writing.

2) Don't use "on submit" for the entire form. Just put an "on click" event that's tied to the final submit button of your form.

3) Get rid of the extra submit button for your "emp ID" (I guess "employee ID" - you can tell by now I like to actually write variables out to reduce confusion) and create a listener by adding an "on key up" event on the text field/select list and have it fill in the rest of the values automatically without requiring extra user input.

And yes, as Dchuk said, make sure there is also validation on the server in case someone has JavaScript disabled.