2

I have a <form id="foo" action="bar.php" method="post"> that has 2 submit buttons, name="save" and name="lock".

I'm running a jquery function:

$("a#submit").click(function() {
    $("#foo").submit();
});

How can I tell jQuery to submit the name lock and not the other one?

4
  • $("input[name='lock']").click(); why cant you use this? Commented Mar 27, 2015 at 10:09
  • Addition to above comment, better use $("input[name='lock']")[0].click(); Commented Mar 27, 2015 at 10:10
  • One form can only have one action, do you mean you want to click name button then go to action 1, click lock button then go to action 2? Commented Mar 27, 2015 at 10:11
  • The link that I want to use to trigger the form submit is not within the form, which is why I cannot use click(). I want the link to submit a form on the page. But that form has 2 <input type="submit">, one has a name of save and the other has lock. I want to trigger the lock one. Commented Mar 27, 2015 at 10:17

2 Answers 2

1

Save the form by ajax method . You want to save the form with two submit button. For 1 button call the ajax & save. Second button will work as usual.

 $("input[name='lock']").click(function({
       $.ajax({
          url: 'test.php',
          type:'POST',              
          data: $("#fo").serialize();
        })
 }));
Sign up to request clarification or add additional context in comments.

Comments

1

You could trigger a click-event on the button:

$("a#submit").click(function() {
    $( "button[name=lock]" ).trigger( "click" );
});

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.