I'd like to make a click event fire on an <input type="file">
tag programmatically.
Just calling click() doesn't seem to do anything or at least it doesn't pop up a file selection dialog.
I've been experimenting with capturing events using listeners and redirecting the event, but I haven't been able to get that to actually perform the event like someone clicked on it.
Let me add to this old post, a working solution I used to use that works in probably 80% or more of all browsers both new and old.
The solution is complex yet simple. The first step is to make use of CSS and guise the input file type with "under-elements" that show through as it has an opacity of 0. The next step is to use JavaScript to update its label as needed.
Working jsFiddle Example
You can do this as per answer from Open File Dialog box on <a> tag
My solution for Safari with jQuery and jQuery-ui:
Hopefully this helps someone - I spent 2 hours banging my head against it:
In IE8 or IE9, if you trigger opening a file input with javascript in any way at all (believe me I've tried them all), it won't let you submit the form using javascript, it will just silently fail.
Submitting the form via a regular submit button may work but calling form.submit(); will silently fail.
I had to resort to overlaying my select file button with a transparent file input which works.
Try this solution: http://code.google.com/p/upload-at-click/
If you want the
click
method to work on Chrome, Firefox, etc, apply the following style to your input file. It will be perfectly hidden, it's like you do adisplay: none;
It's that simple, I tested it works!