Skip to content

Commit

Permalink
Replace alert in canvas_api_tutorial
Browse files Browse the repository at this point in the history
Add eventlistener to form element
  • Loading branch information
evelinabe committed Jul 5, 2024
1 parent 9dee488 commit bfa407f
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 bfa407f

Please sign in to comment.