Javascript DOM HTML Input FileUpload accept Property get

Introduction

Display the accepted content type of a <input type="file"> element:

var x = document.getElementById("myFile").accept;

Click the button below to display the value of the accept attribute of the file upload button.

View in separate window

<!DOCTYPE html>
<html>
<body>

Select a file to upload:
<input type="file" id="myFile" size="50" accept="image/*">
<button onclick="myFunction()">Display accepted file types</button>

<p id="demo"></p>

<script>
function myFunction() {//from   ww w . j  av  a  2  s .  c o  m
  var x = document.getElementById("myFile").accept;
  document.getElementById("demo").innerHTML = x;
}
</script>

</body>
</html>



PreviousNext

Related