subash
subash

Reputation: 4137

'Accept' attribute of input element is not working

I came across a browse file dialog-control tag in html and the tag was

<input id="myfile" name="myfile" type="file" accept="application/pdf"/>

but the 'accept' attribute doesn't seems to have any effect. I am using Internet Explorer 8.

Upvotes: 6

Views: 30619

Answers (4)

Jacob
Jacob

Reputation: 273

I know this is an old question, but I found that for me it was my browser cache. Once I opened in incognito it worked just fine.

Upvotes: 0

John
John

Reputation: 13757

Delimiter

HTML5 accept delimiter

I can confirm in some modern browsers that if you want the file dialog types to appear you need to use a comma as a delimiter:

<input accept="image/apng, image/jpeg, image/png" name="example" type="file" />

Upvotes: 1

David Flamme
David Flamme

Reputation: 71

It seems like browsers have trouble following the IANA specifications found here: http://www.iana.org/assignments/media-types/media-types.xhtml

In my case, the application/pkcs* media types don't work at all, while for some reason application/x-pkcs12 works in chrome and partially(.p12) in IE. Firefox seems completely oblivious.

I also found this more optimistic discussion over here. File input 'accept' attribute - is it useful?

So, the best description would be "probably unsupported for uncommon formats", and with the x-pkcs vs pkcs confusion more or less unusable in my case.

Upvotes: 0

ghermeto
ghermeto

Reputation: 174

according to the w3schools (http://www.w3schools.com/TAGS/att_input_accept.asp), the 'accept' attribute is not properly supported by any of the major browsers. The filter inside the file browser dialog will not work.

You could use a javascript validation on the form onsubmit event to verify if the file type is correct, returning false otherwise.

Upvotes: 15

Related Questions