2

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 2

1

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);
    });
 }
Sign up to request clarification or add additional context in comments.

1 Comment

@InventorBala Glad that I was able to help. If this answered your question, please check the checkmark next to the answer to resolve your question as answered/solved.
0

You have very confusing code. See my short example:

$("input[type=file]").on("change",function (){
  var numFiles = $(this)[0].files.length;
  alert(numFiles);
 });

And in playground with your code: https://jsfiddle.net/denisstukalov/q9xau5yr/6/#&togetherjs=BjIDOeQOoo

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.