Java Reference
In-Depth Information
<script type=”text/javascript”>
// Equation is °C = 5/9 (°F - 32).
var degFahren = prompt(“Enter the degrees in Fahrenheit”,50);
var degCent;
degCent = 5/9 * (degFahren - 32);
alert(degCent);
</script>
</body>
</html>
If you load the page into your browser, you should see a prompt box, like that shown in Figure 2-3, that
asks you to enter the degrees in Fahrenheit to be converted. The value 50 is already fi lled in by default.
Figure 2-3
If you leave it at 50 and click OK, an alert box with the number 10 in it appears. This represents 50
degrees Fahrenheit converted to centigrade.
Reload the page and try changing the value in the prompt box to see what results you get. For example,
change the value to 32 and reload the page. This time you should see 0 appear in the box.
As it's still a fairly simple example, there's no checking of data input so it'll let you enter abc as the
degrees Fahrenheit. Later, in the “Data Type Conversion” section of this chapter, you'll see how to spot
invalid characters posing as numeric data.
Try It Out Security Issues with Internet Explorer 8
When loading the page to Internet Explorer 8 (IE8), you may see the security warning issue shown in
Figure 2-4, and the prompt window doesn't appear.
To help protect your security, Internet Explorer has restricted this webpage from running scripts or ActiveX controls that could
access your computer. Click here for options...
Figure 2-4
Search WWH ::




Custom Search