I have a simple question about the semantic part. button
I can modify your actions using Javascript . When should I use it or exchange it with submit
?
<input type="button"> e <input type="submit">
I have a simple question about the semantic part. button
I can modify your actions using Javascript . When should I use it or exchange it with submit
?
<input type="button"> e <input type="submit">
<button type="submit"
and <button type="button"
The difference is that type="submit"
submits a form in which this button is inserted; while type="button"
has no default action.
Via JavaScript can intercept the submit
event in case, for example, you want to do a validation of the data entered in the form. type="button"
does nothing more than be a button and trigger whatever code JavaScript might have for it.
<input type="submit"
and <button type="submit"
They are similar but different. Semantics should be the choice factor:
User input : use input Click a button : use button
"Formerly" when browsers were less predictable and acted more unpredictably (I'm mainly talking about IE) input type="submit"
was the safest.
The great advantage of button
is that you can have HTML inside while input
is auto-closed and the text it shows is defined in the value
attribute.
Do not forget that the button without type="button"
, that is, without a defined type, acts as a type="submit"
, this is its default functionality.
Button :
Input :