Example
Change the accepted content type:
// The server will only accept audio files in the file upload
document.getElementById("myFile").accept = "audio/*";
Try it Yourself »
Definition and Usage
The accept property sets or returns the value of the accept attribute of the file upload button.
The accept attribute specifies the types of files that the server accepts (that can be submitted through a file upload).
Browser Support
Property | |||||
---|---|---|---|---|---|
accept | Yes | Not supported | Yes | Not supported | Yes |
Syntax
Return the accept property:
fileuploadObject.accept
Set the accept property:
fileuploadObject.accept="audio/*,video/*,image/*,MIME_type"
Property Values
Tip: To specify more than one value, separate the values with a comma.
Value | Description |
---|---|
audio/* | All sound files are accepted |
video/* | All video files are accepted |
image/* | All image files are accepted |
MIME_type | A valid MIME type, with no parameters. Look at IANA MIME types for a complete list of standard MIME types |
Technical Details
Return Value: | A String, containing a comma-separated list of accepted content types |
---|
More Examples
Example
Display the accepted content type of a <input type="file"> element:
var x = document.getElementById("myFile").accept;
The result of x could be:
image/*
Try it Yourself »
Example
Accept multiple content types:
// The server will only accept audio and video files in the file upload
document.getElementById("myFile").accept = "audio/*,video/*";
Try it Yourself »
Related Pages
HTML reference: HTML <input> accept attribute
< Input FileUpload Object