Lesson 2 of 8

Two linked fields

Goal

A field whose validity depends on another

01

Explanation

A "Confirm password" field doesn't stand on its own: whether it's valid depends on another field, so the required attribute isn't enough here.

The rule is that a change to either field revalidates both. If you attach the event listener to the second field only, you leave a gap: the user may fix the first field and still see the error, even though the two fields now match.

02

Your task

Make #confirm invalid as long as it doesn't match #pass, and revalidate whenever either of them changes.

Checks

4 checks
  1. Matching values make the confirm field valid
  2. Different values make it invalid
  3. Editing the first field revalidates too
  4. A message appears when they don't match
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%
–/4

Press “Run and check” to grade your code.

4 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.