Trigger File Input Dialog June 23, 2022 Post a Comment How can I auto trigger file input? ie. in the link below I want to trigger upload button on load DEMO Solution 1: File input can't be automatically triggered in onload due to security purpose. It can't be fired without any user interaction. It is very disgusting when a page activates anything itself when the page loads. By the way. You can use label instead of button like following: <label for="test">Upload</label> Copy Solution 2: $("document").ready(function() { setTimeout(function() { $("#test1").trigger('click'); },10); $('#test1').click(function(){ alert('hii'); }) }); Copy click event triggerd. http://jsfiddle.net/j9oL4nyn/1/ Solution 3: you can write something like this $(document).ready(function(){ $("input#test").click(); }); Copy this should work fine Solution 4: The problem with your code is that you are applying a click event to the input and also to the div enclosing the button, but not to the actual button. if you change your fiddle to this <form id="test_form"> <input type="file" id="test"> <div id="test1"><button onclick="alert('click');">Upload</button></div> </form> Copy and $("#test1 button").trigger('click'); Copy then the click trigger will be applied to the button. Alternatively give your button an ID and fo $("#buttonid").trigger('click'); Copy Solution 5: You can do it somthing like as : <button id="upld_btn">Upload</button> $(document).ready(function () { $('#upld_btn').trigger('click'); }); Copy Share Post a Comment for "Trigger File Input Dialog"
Post a Comment for "Trigger File Input Dialog"