Trigger File Input Dialog October 09, 2023 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:<labelfor="test">Upload</label>CopySolution 2: $("document").ready(function() { setTimeout(function() { $("#test1").trigger('click'); },10); $('#test1').click(function(){ alert('hii'); }) }); Copyclick event triggerd.http://jsfiddle.net/j9oL4nyn/1/Solution 3: you can write something like this$(document).ready(function(){ $("input#test").click(); }); Copythis should work fineSolution 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> Copyand$("#test1 button").trigger('click'); Copythen the click trigger will be applied to the button. Alternatively give your button an ID and fo$("#buttonid").trigger('click'); CopySolution 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"