Javascript Form How to - Get TYPE attribute of the file upload input box








Question

We would like to know how to get TYPE attribute of the file upload input box.

Answer


 <!--from   w w  w.  j  a va2  s. c  o m-->
<html>
<body>
    <script language="JavaScript">
    function getType(){
         var mytype = document.form1.uploadbox.type;
         console.log("The input box type is: " + mytype);
    }
    </script>
    <form name="form1">
    <input type="file" name="uploadbox">
    <br><br>
    Click on the button below.
    <br>
    <input type="button" value="Get Type" onClick='getType()'>
    </form>
</body>
</html>

The code above is rendered as follows: