Skip to: content, navigation

by Ian Lloyd

value (HTML attribute)

Browser support full matrix
IE5.5+ FF1+ Saf1.3+ Op9.2+
Buggy Full Full Full
Spec
Depr. Version
No HTML 2
value="value"

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

IE5.5Buggy
6.0Buggy
7.0Buggy
Firefox1.0Full
1.5Full
2.0Full
Safari1.3Full
2.0Full
3.0Full
Opera9.2Full

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

The Principles of Beautiful Web Design

Best Seller!

You don’t need to go to Art School to design great looking web sites!

Book Cover: The Principles of Beautiful Web Design

Download the FREE sample chapters