0
<ul id="uploadimages">
    <li><input type="file" name="gallery[]" id="upload1"/></li>
    <li><input type="file" name="gallery[]" id="upload2"/></li>
    <li><input type="file" name="gallery[]" id="upload3"/></li>
    <li><input type="file" name="gallery[]" id="upload4"/></li>
</ul>

How to count how many empty input(type="file") fields inside the <ul> ?

3 Answers 3

2

Working with your example

<ul id="uploadimages">
    <li><input type="file" name="gallery[]" id="upload1"/></li>
    <li><input type="file" name="gallery[]" id="upload2"/></li>
    <li><input type="file" name="gallery[]" id="upload3"/></li>
    <li><input type="file" name="gallery[]" id="upload4"/></li>
</ul>

<input type="button" value="click" class="count"/>

Script in document.ready

$(".count").click(function(){
var count = $('#uploadimages input:file[value=""]').length
alert(count);

})
Sign up to request clarification or add additional context in comments.

Comments

2
$('#uploadimages input:file[value=""]').length

Comments

1

Accepted approach of Murtaza unfortunatelly doesn't work for me. I don't know why. https://jsfiddle.net/7vLrhqyw/

This works:

$(".count").click(function () {
    var count=0;
    $('#uploadimages input:file').each(function(){
       if($(this).val()=="")count++; 
    });
    alert(count);

});

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.