1

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?

2
  • I think you can do thhat with accept attribute of input element. Commented Jul 1, 2014 at 14:09
  • I checked but accept just specifies if you want to use audio, video or image files etc. you cannot specify the extension of the file being selected. Thanks for the help though Commented Jul 1, 2014 at 14:13

1 Answer 1

1

You can use the accept attribute in the input:

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

For more info, see MDN.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.