0

I'm trying to trigger the button click event without having to actually click it. When the page is loaded I want to trigger the click event.

Here's the jsfidde link

<input type="file" id="test">
    <button>Upload</button>

$(document).ready(function () {
    $("button").click(function (e) {
        $("#test").trigger('click');
    });

    $('button').trigger('click');
});
5
  • @Pranav: click event is not working! Commented Sep 10, 2015 at 18:06
  • simple: you can't show the file browser dialog without the user actually clicking on something. just calling click() on it does nothing without a human-initiated input event. Commented Sep 10, 2015 at 18:08
  • I hate to be that guy, but why not use jQuery File Upload? Commented Sep 10, 2015 at 18:10
  • i was trying to use html5 capture camera event. I don't want to click the button every time to take the picture. i was hoping once the picture is taken, i would trigger the camera button event so that user won't have to click on it again. Commented Sep 10, 2015 at 18:18
  • possible duplicate of trigger file upload dialog using javascript/jquery Commented Sep 10, 2015 at 18:43

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.