HTML/Elements/output

From Web Education Community Group
< HTML‎ | Elements
Jump to: navigation, search

<output>

The <output> element represents the result of a calculation.

HTML Attributes

  • for = unordered set of unique space-separated tokens
    Allows an explicit relationship to be made between the result of a calculation and the elements that represent the values that went into the calculation or that otherwise influenced the calculation.
    This attribute must have the value of an ID of an element in the same Document.[Example B]


  • form = the ID of a form element in the element's owner
    Associate the output element with its form owner.
    By default, the output element is associated with its nearest ancestor form element.


  • name = unique name
    Represents the element's name.


See also global attributes.


Examples

Example A

A simple calculator could use output for its display of calculated results [try it]:

<form onsubmit="return false" oninput="o.value = a.valueAsNumber + b.valueAsNumber">
 <input name=a type=number step=any> +
 <input name=b type=number step=any> =
 <output name=o></output>
</form>

Output01.png

Example B

The following example is the one for the use of the for attribute [try it]:

<form onsubmit="return false" oninput="o.value = a.valueAsNumber + b.valueAsNumber">
 <input name=a type=number step=any> +
 <input name=b type=number step=any> =
 <output name=o for="a b"></output>
</form>

Output02.png

HTML Reference

The HTML5 specification defines the <output> element in 4.10.15 The output element.