Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to handle onchange event on input type=file in jQuery?

The code is:

<input ID="fileUpload1" runat="server" type="file"

The following works fine:

<input onchange="javascript:alert('hola');" ID="fileUpload1"  runat="server" type="file"

I'd like to get this result using jQuery, but that doesn't work:

$('#fileUpload1').change(function (e) {
    alert("hola");
});

I am missing something? (Edit: Yes I missed include the *.js file.)

like image 495
anmarti Avatar asked Aug 08 '12 08:08

anmarti


2 Answers

Demo : http://jsfiddle.net/NbGBj/

$("document").ready(function(){

    $("#upload").change(function() {
        alert('changed!');
    });
});
like image 159
Shabnam K Avatar answered Nov 02 '22 14:11

Shabnam K


Or could be:

$('input[type=file]').change(function () {
    alert("hola");
});

To be specific: $('input[type=file]#fileUpload1').change(...

like image 12
Alex Ball Avatar answered Nov 02 '22 15:11

Alex Ball