Lesson 2 of 8
Two linked fields
- 12 min
- 4 checks
- 3 hints
- Go to task
Goal
A field whose validity depends on another
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.
Your task
Make #confirm invalid as long as it doesn't match #pass, and revalidate whenever either of them changes.
Checks
4 checks- Matching values make the confirm field valid
- Different values make it invalid
- Editing the first field revalidates too
- A message appears when they don't match