views:

36

answers:

2

How can I detect when a user has chosen which file to upload using a html file input. That way I can submit the form automatically.

+1  A: 

The file upload element fires an onchange event when its contents have changed. Here's a very terse example:

<input type="file" name="whatever" onchange="alert('Changed!');" />

EDIT: Oh, and if you'd like to submit the form when they select something (although this will probably be a little confusing to your users):

<input type="file" name="whatever" onchange="this.form.submit();" />
Faisal
Just noticed that you're using jQuery, in which case you'll want to use the change() event like Reigel suggested.
Faisal
+3  A: 

try

$('#inputfileID').change(function(){
alert(0);
})​
Reigel