How to find out which submit button was clicked when you have multiple submit buttons?

Hi, I have a form with 3 submit buttons.  I need to know which one was clicked though, so that my form validation function knows which part of the form to validate.  Does anyone know how to determine which submit button as clicked in a form?
FairyBusinessAsked:
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.

mrh14852Commented:
Something like this.

<!DOCTYPE html>
<html>
<head>
    <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
    <script type="text/javascript">
        $(document).ready(function(){
            $('.form-button').click(function(){
                if ($(this).attr('id') === 'button1'){
                    alert('b1');
                    //validation code
                }
                if ($(this).attr('id') === 'button2'){
                    alert('b2');
                    //validation code
                }
                if ($(this).attr('id') === 'button3'){
                    alert('b3');
                    //validation code
                }
            });
        });
    </script>
</head>
<body>
<input type="button" id="button1" class="form-button" value="Button1" />
<input type="button" id="button2" class="form-button" value="Button2" />
<input type="button" id="button3" class="form-button" value="Button3" />
</body>
</html>

Open in new window

0

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
FairyBusinessAuthor Commented:
Does this work for submitting a form though? I have .submit not .click.

    $("userForm").submit(function () {

Open in new window

0
FairyBusinessAuthor Commented:
correction, I have this in my code:

$("#userForm").submit(function () {

Open in new window

0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

mrh14852Commented:
Well you said you had multiple buttons.

Can you post your full form code please.
0
FairyBusinessAuthor Commented:
I've requested that this question be closed as follows:

Accepted answer: 0 points for FairyBusiness's comment http:/Q_27521990.html#37383361

for the following reason:

I got it working, thanks.<br />I just put the .submit function inside of the .click function.
0
FairyBusinessAuthor Commented:
I didn't mean to delete this question. I wanted to accept a solution.
0
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
JavaScript

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.