Javascript Form How to - Get type property of the select box








Question

We would like to know how to get type property of the select box.

Answer


<!--from  ww w. ja  va 2s .  c  om-->
<html>
<head>
    <script language="JavaScript1.1">
    function getType(){
      console.log("The name of this text box is " + document.myForm.elements[0].type);
    }
    </script>
</head>
<body>
    <form name="myForm">
      <select name="mySelect">
        <option value=A>AA</option>
        <option value=B>BB</option>
        <option value=C>CC</option>
        <option value=D>DD</option>
      </select>
      <input type=BUTTON value="Get Type" name="myButton" onClick='getType()'>
    </form>
</body>
</html>

The code above is rendered as follows: