value (HTML attribute)
Example
This markup defines different
value attributes for two submit
buttons:
<form>
⋮
<button accesskey="b" name="cmdsubmitter1"
type="submit" value="blue">
Take the <strong style="color:blue;">blue</strong> pill
</button>
<button accesskey="r" name="cmdsubmitter2"
type="submit" value="red">
Take the <strong style="color:red;">red</strong> pill
</button>
</form>
Description
The button
element has the potential to encapsulate a number of different HTML
elements and a range of content. HTML authors are unable to access the
data submitted via this element. The value
attribute can be used to alleviate this issue, although the most common
scenario sees value used to identify which of a
series of button elements a user clicked on, and to
behave accordingly, as suggested in the example above.
Value
This attribute can take any name or value that the developer chooses.
Compatibility
| IE | 5.5 | Buggy |
|---|---|---|
| 6.0 | Buggy | |
| 7.0 | Buggy | |
| Firefox | 1.0 | Full |
| 1.5 | Full | |
| 2.0 | Full | |
| Safari | 1.3 | Full |
| 2.0 | Full | |
| 3.0 | Full | |
| Opera | 9.2 | Full |
The support for this element-specific attribute is good (where the browser supports the element itself).
Internet Explorer misbehaves slightly with the
value attribute—it incorrectly submits the text
content that’s contained within the opening <button>
and closing </button> tags, rather than that contained in
the value attribute. In addition, Internet Explorer
doesn’t seem to care which of the button elements in a
group was pressed—no matter which one the user presses, you’ll only get
the data associated with the final button in the
group!
User-contributed notes
There are no comments yet.
Add a note
To post a note on this topic, please log in with your SitePoint username and password. If you don't have an account yet, you can create a new account for free.

