Monday, July 26, 2010

The <button> Element

The button element is used to submit or clear forms, or to perform an action using Javascript. Unlike input element, which is also used to create buttons, button is not an empty element and therefore all its content serves as the button. The button element can contain almost any element, inline or block. The exceptions are the a, form, fieldset, input, select, textarea, label and button.

The button element, like inline elements, needs to have a block parent element such as p or div. Unlike inline elements, however, it can contain child block elements.

Example: <form action="form.php"><div><button><p>the quick brown</p></button></div></form>

Attributes

disabled="disabled"

With this attribute, the button is disabled (grayed-out).

type

The value of this attribute can be submit, which submits the form that the button is contained in, reset, which clears all the form's entries, or button which is used when the action is defined by Javascript. Without the type attribute, button functions like a submit button.

name

This specifies the control name of the button.

value

The value of this attribute is sent together with the control name of the button.

Example: <form action="test.php"><p><button name="somename" value="somevalue">the quick brown</button></p></form>

When the button is clicked it will send test.php?somename=somevalue

No comments: