topical media & game development

talk show tell print

basic-web-html-11-ch11-eg08.htm / htm

  <?xml version="1.0" ?>
  <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
  <html xmlns="" lang="en" xml:lang="en">
  <title>Conditional statements</title>
  <script type="text/JavaScript"> 
  function checkAnimal() {
  switch (document.frmAnimal.txtAnimal.value){
  case "rabbit": 
  alert("Watch out, it's Elmer Fudd!")
  case "coyote": 
  alert("No match for the road runner - meep meep!")
  case "mouse": 
  alert("Watch out Jerry, here come Tom!")
  default : alert("Are you sure you picked an animal?");
  <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()" />
  <p>Note that rabbit, coyote, and mouse will all get different responses.</p>

(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.