Lesson 4 of 8

Submit only once

Goal

Stop a double click from placing two orders

01

Explanation

The user clicks "Buy" and nothing seems to change, so they click again. The result is two orders, two shipments, and then a call to customer support.

The protection comes in two layers. A guard in the code is a variable that stops a second submission from running before the first one finishes. A guard in the UI means you disable the button and change its text so the user can see that something is happening.

Neither one is enough on its own. The variable alone shows the user nothing, and disabling the button alone doesn't protect the code, because the submit event can come from somewhere other than the button.

02

Your task

Make the order go out only once no matter how many times the button is clicked, and restore the button when the request finishes.

Checks

5 checks
  1. Rapid repeated submits send a single order
  2. The button is disabled while sending
  3. The button works again when it's done
  4. The page doesn't reload on submit
  5. You can submit again after the first order finishes
03

Hints

0/3
Track lessons0 of 8 done

In this track you'll write your own validation rules, tie one field to another, and write error messages a screen reader can announce.

Intermediate level, 8 lessons, 1.5 hours in total.

index.html
Preview
index.html100%
–/5

Press “Run and check” to grade your code.

5 checks listed under “Your task”.

Track lessons0 of 8 done

In this track you'll write your own validation rules, tie one field to another, and write error messages a screen reader can announce.

Intermediate level, 8 lessons, 1.5 hours in total.