Select box value on <select> and show the value in the textfield - Javascript DOM HTML Element

Javascript examples for DOM HTML Element:Select

Description

Select box value on <select> and show the value in the textfield

Demo Code

ResultView the demo in separate window

<html>
   <head> 
      <script type="text/javascript">
   function assignText(obj) {/*w ww.j a va 2s.c o  m*/
    document.getElementById("textboxid").value = obj.options[obj.selectedIndex].value;
   }

      </script> 
   </head> 
   <body> 
      <form action="#" method="post"> 
         <select name="select" id="slectboxid" onchange="assignText(this)"> 
            <option value="test">test</option> 
            <option value="test2">test2</option> 
         </select> 
         <input type="text" name="text" id="textboxid"> 
      </form>  
   </body>
</html>

Related Tutorials