Mega Code Archive

 
Categories / JavaScript Tutorial / Form
 

Using the options[index] text Property

< html>  <head>  <title>Color Changer 1</title>  <script type="text/javascript">  function seeColor(form) {      var newColor = (form.colorsList.options[form.colorsList.selectedIndex].text);      document.bgColor = newColor;  }  </script>  </head>  <body>  <form>  <select name="colorsList">      <option selected="selected">Gray</option>      <option>Yellow</option>      <option>Black</option>      <option>Red</option>  </select> <input type="button" value="Change It" onclick="seeColor(this.form)" /> </form>  </body>  </html>