vincent vincent - 7 months ago 11
Javascript Question

triggering a file input button

I have the following situation:

<input id="upload_trigger_btn" type="file" name="files[]" multiple>
<a type="submit" class="button-normal-12px-ffffff" href="#"><span>Add files</span></a>

$(".add_files_btn").bind("click", function () {
$("#upload_trigger_btn").trigger("click");
});


So basically i want to trigger the file input button using another. This works great in firefox and IE but the button doesn't get triggered in chrome and safari.

Answer

I think you could get away with:

$(".add_files_btn").unbind("click").bind("click", function () {
   $("#upload_trigger_btn").click();
});
Comments