Javascript DOM HTML Input FileUpload form Property get

Introduction

Get the id of the form containing the <input type="file"> element:

var x = document.getElementById("myFile").form.id;

Click the button below to display the id of the form containing the file button.

View in separate window

<!DOCTYPE html>
<html>
<body>

<form id="myForm">
  Select a file to upload:
  <input type="file" id="myFile">
</form>//ww w.ja v  a 2s . c  o  m
<button onclick="myFunction()">Test</button>

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

<script>
function myFunction() {
  var x = document.getElementById("myFile").form.id;
  document.getElementById("demo").innerHTML = x;
}
</script>

</body>
</html>

The form property returns a reference to the form containing the file upload button.

This property returns a form object on success.

This property is read only.

If the file upload button is not in a form, null is returned




PreviousNext

Related