Javascript DOM HTML Input FileUpload Object create

Introduction

We can create an <input> element with type="file" via the document.createElement() method:

var x = document.createElement("INPUT"); x.setAttribute("type", "file");

Click the button to create a File Upload Button.

View in separate window

<!DOCTYPE html>
<html>
<body>

<button onclick="myFunction()">Test</button>

<script>
function myFunction() {/* www  .  j a  v  a 2 s. c  o  m*/
  var x = document.createElement("INPUT");
  x.setAttribute("type", "file");
  document.body.appendChild(x);
}
</script>

</body>
</html>



PreviousNext

Related