Directions: Type a known value into the left column. Then click anywhere outside the cell you just filled. The answer will appear in the column to the right. JavaScript Programmers see below.
Length (feet, meters)
Area (square feet, square meters)
Mass and Weight (ounces,grams)
Liquid Volume (pints, liters)
Temperature (Fahrenheit, Celsius
This example actually contains very little JavaScript code. Between the
and tags in this page is the one and only JavaScript function that does all the calculations. That function, named calc(), is shown below:Each cell that the reader is allowed to type in contains an onchange event handler that's triggered after the reader types something and leaves the cell. Each cell passes passes three values to the calc() JavaScript function, 1) the value the reader typed into the cell (this.value), 2) the conversion factor needed to do the math (25.4 in the example below), and 3) the name of the field to put the result in ("cmillimeters" in the example below).
onChange="calc(this.value,25.4,'cmillimeters')"
Each field that displays an answer is made "read-only" so the user can't type over the calculated answer. To make a field read-only, make it lose the focus (blur()) as soon as it gets the focus (onfocus).