This is a very rudimentary question, but I am sure someone out there knows why. In HTML, when I make a button element by itself, and do not give it and onclick
and no jQuery .click()
the button will just do nothing. Perfect. But when I do this and but the button inside a <form>
element, it tries to send GET data of all the form elements to the root address of my website? Why is it doing that? I didn't make it a submit button or even define a method
or action
on that form??
Thanks for the info in advance!
** EDIT **
This is what I did to fix the problem. For buttons inside the <form>
, use:
<button type="button"></button>
And it will not do anything by default.
As can be seen at the respective MDN entry, the default value for the type
property of a button element is submit
. So if you omit it or don't change it to button
or reset
, the default behaviour will kick in and the form gets submitted.
<form action="">
<button type="button">Nothing will happen</button>
<button>Form gets submitted</button>
</form>
I didn't make it a submit button
<button>
elements have a type
attribute. The default value is submit
. Set type="button"
if you don't want it to submit a form.
or even define a method
method
defaults to GET
or location on that form??
action
defaults to the current URI.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With