Checking Fields against Each Other

It’s common to want to check one field against another, especially when you’re asking the user to type in a password. You want to make them type it in twice for accuracy, and you want to make sure that they typed the same thing both times.

This example reuses Scripts 7.5 (HTML) and 7.6 (CSS); and only a few lines of JavaScript need to be added to Script 7.7 (Script 7.8) to give the script the extra crosschecking functionality. The result is shown in Figure 7.6; once again, when the check fails, the off ending field gets a red border.

Figure 7.6. The two password fields cross-check to make sure their contents are identical. In this case, not so much.

Script 7.8. Use this script to compare the value of one ...

Get JavaScript and Ajax for the Web: Visual QuickStart Guide, Seventh Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.