One form, two submit buttons w/ different javascript validation

This might be pretty simple, but its been bugging me all day. I have a form that
can be submitted in two states, therefore requiring two differnt validation scripts.
As well, each submit needs to go to a differnt action page :).

Right now, I have submit buttons w/ onClick handelers to send the user to the right page.

I can't seem to get the validation to work properly. Is it possible to pass a variable when the
submit is pressed and there for run only a portion of the validation (if (var is defined) {run validation}; etc?
As well, what would my onSubmit look like?

Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Carl TawnSystems and Integration DeveloperCommented:
You might be better off replacing your Submit buttons with standard buttons. Then using the onclick handler and validation routines to actually submit the form:

  <input type="button" name="Submit1" value="Submit1" onclick="ValidateAndSubmit('list or parameters');" />
  <input type="button" name="Submit2" value="Submit2" onclick="ValidateAndSubmit('list or parameters');" />

  <script language="javascript">
    function ValidateAndSubmit( arg1, arg2, etc )
        if (arg1 == 'Something')
             // Set form "action" and validate based on button 1
             // Set form "action" and validate based on button 2

        // Submit the form

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
You can use only one submit button, as shown in the following example:


            <script language="javascript">
                  function decide(s)
                        if (s=="Hello")
                              //validate using first method
                              alert("You didn't write Hello");
                              //validate using second method
                  <input type="text" name="text1"/>
                  <input type="submit" value="Say" onclick="decide(text1.value);"/>


The JavaScript function should receive whatever parameters that will be used to determine the validation method.
Next, the JavaScript code will then determine the validation method to use according to the value(s) of the parameter(s) passed to the function.


  Nayer Naguib
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.