Input Field Management
Managing input fields is the most common application for Javascript.
Here's an example form and its source code.
It uses techniques we've seen before. Observe:
- the focus
method, invoked for user convenience, both onLoad and when an error is
detected
- checks the length of the user-entered string
- placement of the Javascript code within an <INPUT> tag --
- not in the <HEAD>
- not in a function{}
- easier to code small event handlers this way
Lab
Your task:
- Copy the example and edit it as follows.
- Add a Retype Password field.
- If the strings don't match, clear both fields, complain, and place the cursor back into
the first field.
Solution
Don't peek unless you're stuck!
Extra for Experts
- Require your user to enter a mixed-case password.
- Reject it if it's all upper-case or all lower-case.
- Solution