-1

Possible Duplicate:
Jquery trigger file input

I'm developing an app that needs the user to specify a file from the very beginning. I would like to have the file input box display immediately, instead of requiring the user to click an upload button.

Can someone explain to me why the third option works in my jsfiddle example while the others don't? Links to official specs would be most appreciated.

http://jsfiddle.net/vnS3k/

// Trigger Click Event at Load - Doesn't Work
$('#a').click();

// Trigger Click Event at Timeout - Doesn't Work
window.setTimeout(function() {
    $('#a').click();
}, 3000);

// Trigger Click Event at User Click *On Something Else* - Works
$('#b').click(function() {
    $('#a').click();
});
Community
  • 1
  • 1
savinger
  • 6,544
  • 9
  • 40
  • 57

1 Answers1

0

This may be because of security issues around the file input. Browsers don't like you messing around with the file input to prevent bad things. So what may be happening is that it knows the difference between the user clicking and jQuery firing the click event.

In JavaScript can I make a "click" event fire programmatically for a file input element?

Community
  • 1
  • 1
jholloman
  • 1,959
  • 14
  • 16