Internet Explorer does not support the multiple
attribute for <input type="file" />
. However, its not only IE that lacks this support... also certain mobile browsers do not support the multiple
attribute. So simply detecting that the browser is IE is not the ideal solution.
So how would I detect if the multiple
attribute is supported for for <input type="file" />
with JavaScript?
It seems like Modernizr has support for new HTML5 input element attributes:
http://modernizr.com/docs/#input
The accepted solution seems to work, however, since I'm already using Modernizr, my solution is the following:
/**
* Determines if the given attribute is supported for <input /> elements.
*
* @param attribute - the attribute to test for (ex. "multiple")
*/
function isInputAttributeSupported(attribute) {
return (Modernizr.input[attribute]) ? true : false;
};
The multiple attribute is a boolean attribute. When present, it specifies that the user is allowed to enter more than one value in the <input> element. Note: The multiple attribute works with the following input types: email, and file.
The multiple attribute in HTML allows user to enter more than one value. It is a Boolean attribute and can be used on <input> as well as <select> element, To allow multiple file uploads in HTML forms, use the multiple attribute. The multiple attribute works with email and file input types.
The input element, having the "file" value in its type attribute, represents a control to select a list of one or more files to be uploaded to the server. When the form is submitted, the selected files are uploaded to the server, along with their name and type.
HTML 5 has a property for input tag which is 'multiple'.
You can try checking for the existence of the corresponding property:
var supportsMultipleFiles = 'multiple' in document.createElement('input');
Example: http://jsfiddle.net/sbZvS/
var inp = document.createElement("input");
inp.setAttribute("multiple", "true");
var supportsMultiple = inp.multiple===true;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With