When using input type="button" or input type="submit"

6

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">
    
asked by anonymous 30.10.2014 / 18:17

1 answer

8

Ask the difference between <button type="submit" and <button type="button"

The difference is that type="submit" does the submit of 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.

Ask the difference between <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 :

  • Different types: submit, reset, button

Input :

  • Different types: color, date, datetime, datetime-local, email, month, number, range, search, tel, time, url, week, text, file, hidden, image, month, radio, reset, password, and submit
30.10.2014 / 18:29