Javascript Reference - HTML DOM Input FileUpload form Property








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

Browser Support

form Yes Yes Yes Yes Yes

Syntax

var v = fileuploadObject.form 

Return Value

A reference to the form element containing the file upload button. If the file upload button is not in a form, null is returned.





Example

The following code shows how to get the id of the form containing the <input type="file"> element.


<!DOCTYPE html>
<html>
<body>
<!--from w w  w .ja v  a 2 s.co m-->
<form id="myForm">
  Select a file to upload:
  <input type="file" id="myFile">
</form>
<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 code above is rendered as follows: