
- HTML Tutorial
- HTML - Home
- HTML - Overview
- HTML - Basic Tags
- HTML - Elements
- HTML - Attributes
- HTML - Formatting
- HTML - Phrase Tags
- HTML - Meta Tags
- HTML - Comments
- HTML - Images
- HTML - Tables
- HTML - Lists
- HTML - Text Links
- HTML - Image Links
- HTML - Email Links
- HTML - Frames
- HTML - Iframes
- HTML - Blocks
- HTML - Backgrounds
- HTML - Colors
- HTML - Fonts
- HTML - Forms
- HTML - Embed Multimedia
- HTML - Marquees
- HTML - Header
- HTML - Style Sheet
- HTML - Javascript
- HTML - Layouts
- HTML References
- HTML - Tags Reference
- HTML - Attributes Reference
- HTML - Events Reference
- HTML - Fonts Reference
- HTML - ASCII Codes
- ASCII Table Lookup
- HTML - Color Names
- HTML - Entities
- HTML - Fonts Ref
- HTML - Events Ref
- MIME Media Types
- HTML - URL Encoding
- Language ISO Codes
- HTML - Character Encodings
- HTML - Deprecated Tags
HTML DOM Input FileUpload required Property
The HTML DOM input FileUpload required property returns and modify the value of required attribute of a file upload input button in HTML.
Syntax
Following is the syntax −
1. Returning required
object.required
2. Modifying required
object.required = true|false
Example
Let us see an example of HTML DOM input file upload required property −
<!DOCTYPE html> <html> <head> <title>HTML DOM file upload required Property</title> <style> body{ text-align:center; } .btn{ display:block; margin:1rem auto; background-color:#db133a; color:#fff; border:1px solid #db133a; padding:0.5rem; border-radius:50px; width:20%; } .show-message{ font-weight:bold; font-size:1.4rem; color:#ffc107; } </style> </head> <body> <h1>file upload required Property Example</h1> <form id="form" method="post" action=""> <fieldset> <legend >Form </legend> <input type="file" required> <input type="submit" class="btn" value="Submit Form" onclick="checkRequired()"> </fieldset> </form> <div class="show-message"></div> <script> function checkRequired(){ var fileBtn=document.querySelector("input[type='file']"); if(fileBtn.value === ""){ document.querySelector(".show-message").innerHTML = "Please Select a File!"; } } </script> </body> </html>
Output
This will produce the following output −
Click on “Submit Form” button without selecting any file:
- Related Articles
- HTML DOM Input FileUpload disabled Property
- HTML DOM Input FileUpload files Property
- HTML DOM Input FileUpload name Property
- HTML DOM Input FileUpload form Property
- HTML DOM Input FileUpload value Property
- HTML DOM Input FileUpload type Property
- HTML DOM Input FileUpload accept Property
- HTML DOM Input FileUpload autofocus Property
- HTML DOM Input FileUpload Object
- HTML DOM Input URL required Property
- HTML DOM Input Week required Property
- HTML DOM Input Search required property
- HTML DOM Input Text required property
- HTML DOM Input Radio required property
- HTML DOM Input Password required property

Advertisements