Skip to content

Commit

Permalink
Fix
Browse files Browse the repository at this point in the history
  • Loading branch information
Josh-Cena committed Oct 2, 2024
1 parent eb5bc91 commit ea6def6
Showing 1 changed file with 19 additions and 10 deletions.
29 changes: 19 additions & 10 deletions files/en-us/web/api/htmloutputelement/defaultvalue/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,25 +19,34 @@ A string.
In the example below, the `defaultValue` still returns the value originally written in the HTML. Changes to {{domxref("HTMLOutputElement.value", "value")}} will not affect the `defaultValue` or its `textContent` in the DOM.

```html
<p>
<input type="number" id="operand1" value="5" />
+
<input type="number" id="operand2" value="7" />
=
<output id="result" for="operand1 operand2">12</output>
</p>
<pre id="output"></pre>
<fieldset>
<legend>Add two numbers</legend>
<p>
<input type="number" id="operand1" value="5" aria-label="First number" />
+
<input type="number" id="operand2" value="7" aria-label="Second number" />
=
<output
id="result"
for="operand1 operand2"
aria-live="polite"
aria-controls="output"
>12</output
>
</p>
</fieldset>
<pre id="logs" aria-live="polite"></pre>
```

```js
const output = document.getElementById("output");
const logs = document.getElementById("logs");
const operand1 = document.getElementById("operand1");
const operand2 = document.getElementById("operand2");
const result = document.getElementById("result");

function updateResult() {
result.value = operand1.valueAsNumber + operand2.valueAsNumber;
output.textContent = `result.defaultValue: ${result.defaultValue}\nresult.value: ${result.value}`;
logs.textContent = `result.defaultValue: ${result.defaultValue}\nresult.value: ${result.value}`;
}

operand1.addEventListener("input", updateResult);
Expand Down

0 comments on commit ea6def6

Please sign in to comment.