HTML why do buttons on forms send data?

This is a very rudimentary question, but I'm sure someone out there knows why. In HTML, when I make a button element on its own, and don’t give it, and onclick and without jQuery .click() , the button just does nothing. Excellent. But when I do this, but the button is inside the <form> element, it tries to send the GET data of all form elements to the root address of my site? Why is this so? I did not make it a submit button or even defined a method or action in this form

Thanks for the info in advance!

** EDIT **

This is what I did to solve the problem. For buttons inside <form> use:

 <button type="button"></button> 

And by default it will not do anything.

+6
source share
4 answers

As can be seen from the corresponding entry

+9
source

I did not send button

Items

<button> have an a type attribute . The default value is submit . Set type="button" if you do not want it to submit the form.

or even define a method

method default GET

or location on this form

action defaults to the current URI.

+4
source

It was designed this way because sometimes you need to know that the WHICH button has been pressed on the server side. If you want the functionality of a button without a button, use the stylized tag A.

0
source

Buttons are treated as controls in forms, not sure why.

The reason it is sent to your root is because you did not specify an action , and therefore the default value is used.

The reason for using GET is because the default method .

To prevent this, add return false; at the end of your onclick button.

0
source

Source: https://habr.com/ru/post/911861/


All Articles