Mega Code Archive

 
Categories / JavaScript Tutorial / Form
 

Select onChange

The onChange event handler is fired when the option selected in the select box is changed. <html>     <head>     <script language="JavaScript">     <!--     function changeBack(form){       for (var i = 0; i < form.mySelect.options.length; i++) {         if (form.mySelect.options[i].selected){           alert("You have selected " + form.mySelect.options[i].text);         }       }     }     -->     </script>     </head>     <body>     <form name="myForm">       <select name="mySelect" onChange='changeBack(this.form)'>         <option value=A>AA</option>         <option value=B>BB</option>         <option value=C>CC</option>         <option value=D>DD</option>       </select>     </form>     </body>     </html>