Understand the web. Build it yourself.

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

HTML / JavaScript · EXAMPLE
<form>
  <button>Show hint</button>
</form>
Give me a hint

Check what a normal button inside a form does when type is omitted.

Read the solution and corrected code
HTML / JavaScript · EXAMPLE
<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.

Read the related guide →

Original exercise by Mario V.W.B.R. Obst with AI assistance. Technical reference: MDN documentation (new tab). Checked September 2026.

Next exercise →