Output For Form Calculation Result

Display live calculation results using the output element bound to form inputs with the for attribute.

HtmlForm Validation

Code

snippet
<form oninput="result.value = (a.valueAsNumber || 0) + (b.valueAsNumber || 0)">
  <fieldset>
    <legend>Addition Calculator</legend>
    <label>A: <input type="number" name="a" value="0" /></label>
    <label>B: <input type="number" name="b" value="0" /></label>
    <label>Result: <output name="result" for="a b">0</output></label>
  </fieldset>
</form>