When you submit a form, does the button that was clicked get posted also?
-
Related: http://stackoverflow.com/questions/954327/hidden-features-of-html/1978039#1978039 – BalusC Jan 25 '11 at 19:45
3 Answers
Yes it does. As long as you set both the name
and value
:
<INPUT name="submit" value="submit" type="submit"/>
In fact you can have multiple submit buttons on the same page and you can detect which one is clicked on by checking for this pair.

- 26,220
- 11
- 79
- 111
-
4
-
1JS on MSIE has also some itchy issues when using `name="submit"` on a form element ;) – BalusC Jan 25 '11 at 19:43
Yes, submit buttons are submitted with their name/value.
But especially when doing i18n, it's recommended to rely only on the name, not the value though so you don't have to check for i18n'd values in your server-side code but just for the existence of certain POST arguments..

- 310,957
- 84
- 592
- 636
If it is part of the submitted form, yes.
When a form is submitted, every one of it's "input" elements are posted; and if you submit a form by clicking it's submit button (which is another input) you'll definitely post it too.
If you don't want to do that, you can always submit you form via javascript : form.submit();
.
You can add a button element to your form and attach a function that submits the form to it's click event.
<button type="button" onclick="document.getElementsByTagName('form')[0].submit();"> Submit the form! </button>
That way you'll have a submit button inside your form that is not submitted:)

- 41,171
- 10
- 96
- 108