All six exercises / Exercise 03
Find the bug
The button that submits unexpectedly
Give a supporting form action an explicit button type.
Observe the evidence
Show hint is inside a form. It should reveal help without sending that form.
Starting code
<form>
<button>Show hint</button>
</form>Working demonstration
This preview is deliberately broken at first. Its behaviour is contained here.
Give me a hint
Check what a normal button inside a form does when type is omitted.
Read the solution and corrected code
<form>
<button type="button">Show hint</button>
</form>The broken control reveals the hint and also triggers form submission. This demo catches submit with preventDefault so nothing is sent and the page does not reload. On a real page, an uncancelled submission would navigate or send data according to the form configuration.
Make the lesson your own
Add a separate sending button labelled Send with type="submit". Explain why each button has a different type.