Arturo Arturo - 4 months ago 50
jQuery Question

Form with two submit buttons

I have a form with two submit buttons as per below.

<form id="choice" name='form' method="POST" action="/">
<button type="submit" name="vote" id="btnMinus" value="1"></button>
<button type="submit" name="vote" id="btnPlus" value="2"></button>

I have this code in order to prevent that the form is not submitted twice. However, it gives a "bad request" error. Seems that it doesn't send the "vote" value. Any ideas?



Following @RoryMcCrossan's comment, you can use a hidden input and set it's value once the button is clicked:

$('#choice button').click(function(e) {  
<script src=""></script>
<form id="choice" name='form' method="POST" action="/">
  <input id="vote-el" type="hidden" name="vote" value="" />
  <button type="submit" name="vote" id="btnMinus" value="1">1</button>
  <button type="submit" name="vote" id="btnPlus" value="2">2</button>