In this web form,
Ponder the source code and observe:
- a for loop
- use of charAt() to extract characters from strings
- use of the focus() method to put the cursor into the field
- the break statement
- the onLoad
and onChange events
- the this object
- the field is cleared when an "error" is detected
- the && comparison operator (logical AND)
- Conditionals: if, else, switch
- Loops: for, while, do while, break, continue
- Object Manipulation: for...in, new, this, with
- Comments: single-line (//) and multi-line (/*...*/)
- Make a copy of the example form and modify it as follows.
text field accepts numbers only.
- You may find the || (logical OR) operator useful.
Don't peek unless you're stuck!