| Refresh | Home EGTry.com

html combo box select onchange event and display selected value


CommentsHTML sourcedisplay in your current browser
<script type="text/javascript">
 function hourChange(selectObj) {
   var selectIndex=selectObj.selectedIndex;
   var selectValue=selectObj.options[selectIndex].text;
   var output=document.getElementById("output");
   //alert(output.innerText);
   output.innerHTML=selectValue;
 }

</script>

<select id="hour" onchange="hourChange(this);">

  <option>1</option>
  <option>2</option>

</select>

<p/>

you selected: <span id="output">1</span>

you selected: 1