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.)
Demo : http://jsfiddle.net/NbGBj/
$("document").ready(function(){
$("#upload").change(function() {
alert('changed!');
});
});
Or could be:
$('input[type=file]').change(function () {
alert("hola");
});
To be specific: $('input[type=file]#fileUpload1').change(...
It should work fine, are you wrapping the code in a $(document).ready()
call? If not use that or use live
i.e.
$('#fileupload1').live('change', function(){
alert("hola");
});
Here is a jsFiddle of this working against jQuery 1.4.4
This jsfiddle works fine for me.
$(document).delegate(':file', 'change', function() {
console.log(this);
});
Note: .delegate() is the fastest event-binding method for jQuery < 1.7: event-binding methods
$('#fileupload').bind('change', function (e) { //dynamic property binding
alert('hello');// message you want to display
});
You can use this one also
Try to use this:
HTML:
<input ID="fileUpload1" runat="server" type="file">
JavaScript:
$("#fileUpload1").on('change',function() {
alert('Works!!');
});