SHuss
SHuss

Reputation: 41

open a particular type of file using input of type="file" in javascript

I am trying to open a file using <input type="file" ...> and display it as text. I want the dialog box that pops up to open the file to show a particular extension of the file like ".txt" or ".jpg" instead of "All Files". how can I do that using javascript alone?

Upvotes: 1

Views: 216

Answers (1)

reaxis
reaxis

Reputation: 1431

You can use the accept attribute in the input:

<input type="file" accept=".txt,.jpg">

For more info, see MDN.

Upvotes: 1

Related Questions