Output For Form Calculation Result
Display live calculation results using the output element bound to form inputs with the for attribute.
Code
<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>How the snippet works
<output> semantically marks a computed result, which screen readers announce as a live region.
The form collects input via type="number" field, each tied to a <label> so every control announces what it is.
Statements that matter
<form oninput="result.value = (a.valueAsNumber || 0) + (b.valueAsNumber || 0)">
<legend>Addition Calculator</legend>
<label>A: <input type="number" name="a" value="0" /></label>
Interactive Tools for This Topic
JSON to Zod Schema ConverterInfer typed Zod z.object schemas from JSON payloads locally, supporting nested objects, merged array shapes, enums, nullable fields, and JSDoc comments.JSON Schema ValidatorValidate JSON data against a JSON Schema definition and get detailed error reports. Supports type checking, required fields, and common constraint validation.JSONL / NDJSON InspectorValidate NDJSON and JSON Lines line-by-line, pinpoint syntax errors by line number, analyze key frequencies and types, and export a pretty JSON array.Credit Card Brand DetectorIdentify the card network from a number's prefix and length, validate the Luhn checksum, and show a masked form and the issuer identification number.
FAQ
- Which non-generic elements does the markup use?
- `<form>`, `<fieldset>`, `<legend>`, `<label>`, `<input>`, `<output>` — each carries native semantics (or a browser behavior) that generic containers do not.
Report a problem with this exampleOpens a pre-filled issue on GitHub.