9

I have the following code:

<p onclick="jQuery('#file').click()">Select a file</p>
<input type="file" id="file" name="file" />

When the user clicks on "Select a file", it's also supposed to open the file browser like when you press on the "Browse" button generated by <input type="file" />, where the user can select a file.

It works fine in Chrome and IE7. How do I make it work in Firefox?

2 Answers 2

11

Trust me, I went to trouble already about that. It will not work on Firefox and I did not find an answer as to how to make it work.

I suspected you are trying to customize the looks of your input file. I suggest, you use opacity. Set opacity of input file to zero, to make it not visible. Then put above it two span element above it. Then you could style the span as much as you like. When you click any of the span, the click on input file is also trigger.

simple demo


added notes:

With that you have the power to change the look of input file. The problem is, opacity won't work on IE6. ;)

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

1 Comment

i want to open filebrowser to get location from user on click of save button.
10

There is a better way to open the dialog (it works across all modern browsers at this time). Just change

jQuery('#file').click();

to

jQuery('#file').trigger('click');

1 Comment

Yes, as per the text of the answer.

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.