Skip to: content, navigation

value (HTML attribute)

Spec
Depr. Version
No HTML 2
Browser support (more…)
IE5.5+ FF1+ SA1.3+ OP9.2+
Buggy Full Full Full

Syntax

value="value"

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.

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>

Value

This attribute can take any name or value that the developer chooses.

Compatibility

Internet Explorer Firefox Safari Opera
5.5 6.0 7.0 1.0 1.5 2.0 1.3 2.0 3.0 9.2 9.5
Buggy Buggy Buggy Full Full Full Full Full Full Full 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.

Related Products

Search