Am trying to trigger an upload box (browse button) using jQuery.
The method I have tried now is:
$('#fileinput').trigger('click');
But it doesn't seem to work. Please help. Thank you.
Am trying to trigger an upload box (browse button) using jQuery.
The method I have tried now is:
$('#fileinput').trigger('click');
But it doesn't seem to work. Please help. Thank you.
You can use LABEL element ex.
This will trigger the input file
Just for the sake of curiosity, you can do something like you want by dynamically creating an upload form and input file, without adding it to the DOM tree:
No need to add the uploadForm to the DOM.
Try this, it's a hack. the Position:absolute is for Chrome and trigger('change') is for IE.
Actually, I found out a really easy method for this, which is:
This way, your file input field can have the css property display on none and still win the trade :)
Based on Guillaume Bodi's answer I did this:
which means it's hidden to start with and then displayed for the trigger, then hidden again immediately.
That's on purpose and by design. It's a security issue.