Skip to content
Advertisement

How to change accept attribute of input type file based on select file type using javascript?

I have a select list like this

JavaScript

I want to change the accept attribute of file input according to the selected FileTypeIndex by JQuery

JavaScript

But it is always “.“, and it won’t change

Advertisement

Answer

You just need to change the datatype of filytypeIndex variable to number using Number() function of javascript.

Because in switch case gives 1,2,3 … it is numbers

Your final code like below

JavaScript
JavaScript
User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement