topical media & game development

talk show tell print

basic-javascript-06-ch6-examp8-IE.htm / htm



  <html>
  <head>
  <script language="JavaScript" type="text/javascript">
  function butRemoveWed_onclick() 
  {
     if (document.form1.theDay.options[2].text == "Wednesday") 
     {
           document.form1.theDay.options.remove(2);
     } 
     else 
     {
        alert('There is no Wednesday here!');
     }
  }
  
  function butAddWed_onclick() 
  {
     if (document.form1.theDay.options[2].text != "Wednesday") 
     {
        var option = new Option("Wednesday",2);
        document.form1.theDay.options.add(option,2);
     }
     else 
     {
        alert('Do you want to have TWO Wednesdays?????');
     }
  }
  
  </script>
  </head>
  <body>
  <form name=form1>
  <select name=theDay size=5>
     <option value=0 selected>Monday
     <option value=1>Tuesday
     <option value=2>Wednesday
     <option value=3>Thursday
     <option value=4>Friday
     <option value=5>Saturday
     <option value=6>Sunday
  </select>
  <BR>
  <input type="button" value="Remove Wednesday" name=butRemoveWed 
     onclick="butRemoveWed_onclick()">
  <input type="button" value="Add Wednesday" name=butAddWed 
     onclick="butAddWed_onclick()">
  <BR>
  </form>
  </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.