0

I have one form with two submit buttons (like in the question Two submit buttons in one form):

<form action="/doit" method="post">
  <input name="commonfield1" />
  <input name="commonfield2" />
  <input type="submit" name="action1" value="Do something" />

  <input type="file" name="file" onchange="this.form.submit()" />
  <input type="submit" name="action2" value="Do something else" />
</form>

When doing onchange="this.form.submit()", which submit is used? How to select if we submit using action1 or action2?

Note: why not having two separate forms? Because the commonfield1 and commonfield2 inputs should be common to both.

Basj
  • 41,386
  • 99
  • 383
  • 673
  • Could be a duplicate of: https://stackoverflow.com/questions/547821/two-submit-buttons-in-one-form – Michael Conard Jun 21 '18 at 15:21
  • @MichaelConard, no I already read this question, it's not. By the way, you can notice I already applied the accepted answer of this question to the code given here. – Basj Jun 21 '18 at 15:22
  • Do the two submit buttons both hit the same server endpoint (the `/doit` action?). If so, what even is the point of having two buttons? I could give a solution if the buttons sent to different end points, but I guess I'm not sure what you're trying to accomplish. – Michael Conard Jun 21 '18 at 15:29
  • @MichaelConard: yes same endpoint `/doit` but I need a way (with a parameter?) to distinguish both buttons. – Basj Jun 21 '18 at 15:39
  • Ah okay, if you're sending a custom action parameter and check which one it is on the server that makes sense. – Michael Conard Jun 21 '18 at 20:18

0 Answers0