topical media & game development

talk show tell print

basic-javascript-06-ch6-examp7.htm / htm



  <html>
  <head>
  <script language=JavaScript>
  function butRemoveWed_onclick() 
  {
     if (document.form1.theDay.options[2].text == "Wednesday") 
     {
        document.form1.theDay.options[2] = null;
     } 
     else 
     {
        alert('There is no Wednesday here!');
     }
  }
  function butAddWed_onclick() 
  {
     if (document.form1.theDay.options[2].text != "Wednesday") 
     {
        var indexCounter;
        var days = document.form1.theDay;
        var lastoption = new Option();
        days.options[6] = lastoption;
        for (indexCounter = 6;indexCounter > 2; indexCounter--)
        {
        days.options[indexCounter].text = days.options[indexCounter - 1].text;
        days.options[indexCounter].value = days.options[indexCounter - 1].value;
        }
        var option = new Option("Wednesday",2);
        days.options[2] = option;
     }
     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.