Example Scripts


Dictionary

This script defines English words. You enter a word. The script directs you to http://www.dictionary.com where your word is automatically defined.

Validate Email Address

JavaScript is often used to validate forms. This script checks the user input for errors. If a user enters an email address with more than one "@" or with successive periods (i.e. jane@mit..edu), the script will generate an error message.

Change the Background Color

This script changes the background color from red to black and then back again.

Record Date and Time

This script reads the system date and time and displays it on the page.

Form Total

This script creates an order form with checkboxes and updates the total price as the user checks and unchecks the boxes. Using JavaScript to perform calculations is much faster than transmitting all the numbers to the server, using the server to perform the addition, and then sending the total back.

Auto Subcategories

This script automatically changes the subcategories listed in a drop-down menu based on the user's first selection. For example, if the user selects "Europe" as the first category, the names of the countries in Europe will be displayed in the second drop-down menu. If the user selects "Asia" as the first category, the names of the countries in Asia will be displayed in the second drop-down menu.