Skip to content

Commit

Permalink
Add eventlistener to form element
Browse files Browse the repository at this point in the history
  • Loading branch information
evelinabe committed Jul 5, 2024
1 parent 60c5046 commit 9355f54
Showing 1 changed file with 7 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -392,7 +392,7 @@ function draw() {
ctx.lineWidth = 10;

// check input
if (document.getElementById("miterLimit").value.match(/\d+(\.\d+)?/)) {
if (document.getElementById("miterLimit").checkValidity()) {
ctx.miterLimit = parseFloat(document.getElementById("miterLimit").value);
}

Expand All @@ -417,11 +417,9 @@ function draw() {
<td>
Change the <code>miterLimit</code> by entering a new value below and
clicking the redraw button.<br /><br />
<form onsubmit="return draw();">
<label for="miterLimit">Miter limit</label>
<input type="number" size="3" min="1" id="miterLimit" />
<input type="submit" value="Redraw" />
</form>
<label for="miterLimit">Miter limit</label>
<input type="number" id="miterLimit" size="3" min="1" />
<input type="submit" id="redraw" value="Redraw" />
</td>
</tr>
</table>
Expand All @@ -432,6 +430,9 @@ document.getElementById("miterLimit").value = document
.getElementById("canvas")
.getContext("2d").miterLimit;
draw();

const redraw = document.getElementById("redraw");
redraw.addEventListener("click", draw);
```

{{EmbedLiveSample("A_demo_of_the_miterLimit_property", "", "180")}}
Expand Down

0 comments on commit 9355f54

Please sign in to comment.