Sunday, March 31, 2013

HTML input and button

HTML input is older, but button is newer, so some old browser versions did not support button, consequently some people advise to use input rather than button.

button supports only three types : button, submit, reset
where as the older counterpart supports 10 types in html 4.01 and around 20 in html 5


For button, different browsers support different default types, where as for input the default type is text.
For IE, default type is submit.

So when you are using button without specifying type, be aware that it might be submit, and it will case a post. This might be a problem when submit behavior is not intended,e.g. you want to do something else ( calculate some value on the form itself) on a button press.

So keep in mind that <button> and <input type="button"> may not be always equivalent, but
<button type="button"> and <input type="button"> are equivalent.


If fact you should know that :
1. button type=“submit” is the same as input type=“submit”
2. button type=“reset” is the same as input type=“reset”
3. button type=“button” is the same as input type=“button”

For a very good explanation on this topic, see : http://nickcowie.com/presentation/s5-button.html

No comments:

Post a Comment