Java Reference
In-Depth Information
At the top of the page you defi ne your two functions to handle the mouseover and mouseout events.
function mouseOver(that)
{
that.src = “Img2.jpg”;
}
function mouseOut(that)
{
that.src = “Img1.jpg”;
}
The function names tell you what events they will be handling. You access the img object for your
<img/> element by passing a reference to the img object to the function. In the mouseover event you
change the src property of the image to Img2.tif, and in the mouseout event you change it back to
img1.tif, the image you specifi ed when the page was loaded.
In the page itself you have your <img/> element.
<img src=”Img1.jpg” name=”myImage” onmouseover=”mouseOver(this)”
onmouseout=”mouseOut(this)” />
Chapter 7
Exercise 1 Question
Using the code from the temperature converter example you saw in Chapter 2, create a user interface for
it and connect it to the existing code so that the user can enter a value in degrees Fahrenheit and convert it
to centigrade.
Exercise 1 Solution
<!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0 Transitional//EN”
“http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd”>
<html xmlns=”http://www.w3.org/1999/xhtml”>
<head>
<title>Chapter 7: Question 1</title>
<script type=”text/javascript”>
function convertToCentigrade(degFahren)
{
var degCent = 5 / 9 * (degFahren - 32);
return degCent;
}
function btnToCent_onclick()
{
Search WWH ::




Custom Search