topical media & game development
basic-web-html-11-ch11-eg08.htm / htm
<?xml version="1.0" ?>
<!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" lang="en" xml:lang="en">
<head>
<title>Conditional statements</title>
<script type="text/JavaScript">
function checkAnimal() {
switch (document.frmAnimal.txtAnimal.value){
case "rabbit":
alert("Watch out, it's Elmer Fudd!")
break;
case "coyote":
alert("No match for the road runner - meep meep!")
break;
case "mouse":
alert("Watch out Jerry, here come Tom!")
break;
default : alert("Are you sure you picked an animal?");
}
}
</script>
</head>
<body>
<p>Enter the name of your favorite type of animal that stars in a cartoon:</p>
<form name="frmAnimal">
<input type="text" name="txtAnimal" /><br />
<input type="button" value="Check animal" onclick="checkAnimal()" />
</form>
<p>Note that rabbit, coyote, and mouse will all get different responses.</p>
</body>
</html>
(C) Æliens
20/2/2008
You may not copy or print any of this material without explicit permission of the author or the publisher.
In case of other copyright issues, contact the author.