Reputation: 20870
I am new to html coding/javascript and the question is about button types. From w3schools website, there are three types of buttons
<button type="button|submit|reset">
form
for submit
button?I notice that if the button is set to be submit
but there is no form around it, http POST is not sent. It makes sense because it does not know what http message to send. But why do we need an extra layer of form
instead of defining the action and http method inside button?
button
-type button?This w3schools page gives examples to submit
and reset
buttons but not button
buttons.
type
default to some value? or is it not required to have a type?One code example I found on this w3schools page has no type
`<button onclick="myFunction()">Click me</button>`
Upvotes: 1
Views: 2147
Reputation: 10899
We do not need form
for submit
button, we need submit
button for form
.
The button submits form when clicked as well as enter
in text
field, but if you have only radio
s, ticks and textarea
s you have to make a button to be able to submit at all.
The type="button"
is default for <button>
tag.
It goes from the <input>
tag: if you write <input type="button">
that will be the same as if you write <button>
. So is for anothe <input>
types: <input type="submit">
and <button type="submit"/>
are same (note that button has closing tag unlike input, so you may put HTML in it.).buttons.
see #2
Upvotes: 0
Reputation: 100
usually Forms are used to send
PHP
)Example:
<form method="POST" action="destination.php">
<input type="text" value="EMail" name="email">
<input type="submit" Value="OK">
</form>
When user clicks on submit button ~> form sends inputed email to destination.php
Securely because of post method.
Upvotes: 1
Reputation: 562
Answer to the first question:
The HTML element <form>
is used to define a form that used to collect information from the user.
The form is what sends the information to another web page. So, the info can be processed.
For the second question:
It is good to use a simple button for a Javascript event. Such as the one you put in your question.
And finally the third question:
No, I don't think it has a default. But I would say if there was a default, I think it would be submit.
Upvotes: 2