i'm not getting files count using in JQuery?

Viewed 27

I'm not getting files to count using in JQuery and I'm using the below html code and jquery function

        <div class="customerimagebox">
        <input multiple="multiple" type="file" name="Update_Merchandising_to_match_AIMM_images[]" class="Update_Merchandising_to_match_AIMM_images" id="Update_Merchandising_to_match_AIMM_images">
        <i class="fa fa-camera" onclick="fileuploadonclick('Update_Merchandising_to_match_AIMM_images',event)" style="color: black;text-align: center;"></i>
        </div>
        <div class="customerimagebox">
        <input multiple="multiple" type="file" name="Employees_in_Proper_Dress_Code_images[]" class="Employees_in_Proper_Dress_Code_images" id="Employees_in_Proper_Dress_Code_images">
        <i class="fa fa-camera" onclick="fileuploadonclick('Employees_in_Proper_Dress_Code_images',event)" style="color: black;text-align: center;"></i>
        </div>

<script>
function fileuploadonclick(classname,event) {
    event.preventDefault();
    $("."+classname+"").val('').click();
    $(document).on("change","."+classname+"",function (){
        var numFiles = $("input#Update_Merchandising_to_match_AIMM_images",this)[0].files.length;
        alert(numFiles);
    });
</script>
}

I'm only getting this error. please check the below image

enter image description here

2 Answers

It works if you adjust your function like this:

 function fileuploadonclick(classname, event) {
    event.preventDefault();
    $("." + classname + "").val('').click();
    $(document).on("change", "." + classname + "", function() {
       var numFiles = $("input#Update_Merchandising_to_match_AIMM_images").prop("files").length;
       alert(numFiles);
    });
 }
Related