HTML DOM इनपुट FileUpload आवश्यक संपत्ति लौटाता है और HTML में एक फ़ाइल अपलोड इनपुट बटन की आवश्यक विशेषता के मान को संशोधित करता है।
सिंटैक्स
निम्नलिखित वाक्य रचना है -
1. वापसी आवश्यक है
object.required
2. संशोधित करना आवश्यक है
object.required = true|false
उदाहरण
आइए हम HTML DOM इनपुट फ़ाइल अपलोड आवश्यक संपत्ति का एक उदाहरण देखें -
<!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> आउटपुट
यह निम्नलिखित आउटपुट देगा -

“फ़ॉर्म सबमिट करें . पर क्लिक करें बिना किसी फ़ाइल को चुने बटन:
