Web server type - 1359Chapter 53 .Application: Calculations and Graphics } else
January 19th, 20081359Chapter 53 .Application: Calculations and Graphics } else { return + ohmage + ohms } } } The selections from the pop-up menus meet the calculation formulas of resistors in the calcOhms() function. Because this function is triggered indirectly by each of the SELECT objects, sending any of their parameters to the function is a waste of effort. Moreover, the calcOhms() function is invoked by the onLoadevent handler, which is not tied to the form or its controls. Therefore, the function obtains the reference to the form and then extracts the necessary values of the four SELECT objects by using explicit (named) references. Each value is stored in a local variable for convenience in completing the ensuing calculation. Recalling the rules used to calculate values of the resistor bands, the first statement of the calculation multiplies the tens pop-up value times 10 to determine the tens digit and then adds the ones digit. From there, the combined value is multiplied by the exponent value of the selected multiplier value. Notice that the expression first assembles the value as a string to concatenate the exponent factor and then evaluates it to a number. Although I try to avoid the eval()function because of its slow performance, the one call per calculation is not a performance issue at all. The evaluated number is passed to the format() function for proper formatting (and setting of order of magnitude). In the meantime, the tolerance value is extracted from its array, and the combined string is plugged into the result text field (which is in a separate form, as described later): // calculate resistance and tolerance values function calcOhms() { var form = document.forms[ rescalc ] var d1 = form.tensSelect.selectedIndex var d2 = form.onesSelect.selectedIndex var m = form.multiplierSelect.selectedIndex var t = form.toleranceSelect.selectedIndex var ohmage = (d1 * 10) + d2 ohmage = eval( + ohmage + e + multiplier[m]) ohmage = format(ohmage) var tol = tolerance[t] document.forms[ ouput ].result.value = ohmage + , + tol } Preloading images As part of the script that runs when the document loads, the next group of statements precaches all possible images that can be displayed for the resistor art. For added scripting convenience, the color names are loaded into an array. With the help of that just-created array of color names, you then create another array (imageDB), which both generates Image objects for each image file and assigns a URL to each image. Notice an important subtlety about the index values being used to create each entry of the imageDB array: Each index is a colorArray entry, which is the name of the color. As you found out in Chapter 37, if you create an array
You want to have a cheap webhost for your apache application, then check apache web hosting services.