Log in / create account | Login with OpenID
DocForge
Programmer's Wiki

HTML/button

From DocForge

An button element within an HTML document represents a button for performing a submit, reset, or some custom action within a form.

A button element can only be placed within a form element.

[edit] Attributes

  • name - Key of the data value within the form.
  • value - Default value of input.
  • type - Defines the type of button. The value must be one of:
    • button - Custom action form button, typically programmed with JavaScript
    • submit - Submit the form to a web server when clicked. This makes the button act almost exactly the same as an input element of type submit. (default)
    • reset - Reset the form when clicked.

A button of type "submit" is almost identical to an input element of type "submit". One difference is that buttons allow for more CSS styling.

[edit] Implementation

The W3C standard for HTML 4 requires that the value of the button within the form must default to the value attribute, just as it does for input elements. Therefore, when a form is submitted to a web server with this button, the value is submitted with the key (name). This is implemented correctly in Firefox and Safari.

The standard also states that the type attribute must default to submit. This is also properly implemented in Firefox and Safari.

However, in Internet Explorer versions 6 and 7, this standard is not implemented correctly. The submit property does not default to submit and therefore must be explicitly stated. IE also submits the inner HTML of the button attribute instead of the value. Even when inspecting the DOM, the value property is ignored and the inner HTML is the button object's value. Altering the value, such as with JavaScript also alters the inner HTML.

[edit] See Also