Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
HTML DOM Input FileUpload accept Property
The HTML DOM Input FileUpload accept property returns a string, which is the value of the accept attribute of FileUpload. User can also set it to a new value.
Syntax
Following is the syntax −
- Returning string value
inputFileUploadObject.accept
- Setting value attribute to a string value
inputFileUploadObject.accept = value
Example
Let us see an example of Input FileUpload accept property −
<!DOCTYPE html>
<html>
<head>
<title>Input FileUpload accept</title>
<style>
form {
width:70%;
margin: 0 auto;
text-align: center;
}
* {
padding: 2px;
margin:5px;
}
input[type="button"]{
border-radius: 10px;
}
</style>
</head>
<body>
<form>
<fieldset>
<legend>FileUpload-accept</legend>
<label for="FileSelect">Upload:
<input type="file" id="FileSelect">
</label><br>
<input type="button" onclick="fileAccept('Audio')" value="Audio">
<input type="button" onclick="fileAccept('Image')" value="Image"><br>
<div id="divDisplay"></div>
</fieldset>
</form>
<script>
var divDisplay = document.getElementById("divDisplay");
var inputFile = document.getElementById("FileSelect");
divDisplay.textContent = 'All Files Accepted';
function fileAccept(fileType) {
if(fileType === 'Audio'){
inputFile.accept = 'audio/*';
divDisplay.textContent = 'Only '+inputFile.accept+' Files';
} else {
inputFile.accept = 'image/*';
divDisplay.textContent = 'Only '+inputFile.accept+' Files';
}
}
</script>
</body>
</html>
Output
This will produce the following output −
After Clicking ‘Audio’ button −

After clicking ‘Image’ button −

Advertisements