HTML | DOM Input FileUpload required Property
The Input FileUpload required Property is used to set or return whether a file in the file upload field must be selected/uploaded before submitting a form.
This property reflects the HTML required attribute.
Syntax:
- Return the required property:
fileuploadObject.required
- Set the required property:
fileuploadObject.required=true|false
Property Values:
true: Return ‘true’ when the file upload field is required.
false: Return ‘false’ when the file upload field is not required.
Return Value: A Boolean value that displays the status of file upload required field.
Examples-1: Return FileUpload required Property.
<!DOCTYPE html> <html> <head> <title> Input FileUpload required Property </title> <style> h1 { color: green; } </style> </head> <body> <center> <h1> Geeks for Geeks </h1> <form action="/action_page.php"> <input type="file" id="myFile" required> <br> <input type="submit" value="Submit"> </form> <p id="demo"></p> <button onclick="myFunction()"> Try it </button> <script> function myFunction() { var x = document.getElementById( "myFile").required; document.getElementById("demo").innerHTML = x; } </script> </center> </body> </html> |
Output:
Before:

After:


Examples-2: Set FileUpload required Property
<!DOCTYPE html> <html> <head> <title> Input FileUpload required Property </title> <style> h1 { color: green; } </style> </head> <body> <center> <h1> Geeks for Geeks </h1> <form action="/action_page.php"> <input type="file" id="myFile"> <br> <input type="submit" value="Submit"> </form> <p id="demo"></p> <button onclick="myFunction()"> Try it </button> <script> function myFunction() { var x = document.getElementById( "myFile").required = "true"; document.getElementById("demo").innerHTML = x; } </script> </center> </body> </html> |
Output:
Before:

After:

Supported Browsers:
- Google Chrome
- Mozilla Firefox
- Edge 10.0
- Opera
- Apple Safari
Recommended Posts:
- HTML | DOM Input FileUpload name Property
- HTML | DOM Input FileUpload value Property
- HTML | DOM Input FileUpload form Property
- HTML | DOM Input FileUpload type Property
- HTML | DOM Input FileUpload multiple Property
- HTML | DOM Input FileUpload files Property
- HTML | DOM Input FileUpload autofocus Property
- HTML | DOM Input FileUpload accept Property
- HTML | DOM Input FileUpload disabled Property
- HTML | DOM Input URL required Property
- HTML | DOM Input Datetime required Property
- HTML | DOM Input Password required Property
- HTML | DOM Input Number required Property
- HTML | DOM Input Text required Property
- HTML | DOM Input Week required Property
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.



