Question: I have basic order form (4 inputs only for testing purposes), i want to count number of inputs (total items) where value is filled in and higher then 0 (basicaly how many products has been ordered, no to confuse with their quantities). When i add products is fine, problems start when I remove items( set them to 0). Could you help me to work it out.

Working jsfiddle: <http://jsfiddle.net/nitadesign/97tnrepg/33/>

And few lines to bring your attention into a right place:

```
function GetOrder(curId){
var order = null;

for(i = 0; i< orders.length; i++){
     if(orders[i].id == curId){
        order = orders[i];
        break;
    }
}

return order;
}

function CalculateTotal(){
var total = 0;
for(i = 0; i< orders.length; i++){
    total = total + orders[i].packTotal;
}
console.log(total);

if(total > 0){
    $("#order_total").html('Total Items:' + i + '<br>' + 'Order Subtotal: ' + total);
    $("#order_total").show();
    $('.submitorder').show();
}
if(total == 0){
    $("#order_total").html('Your shopping basket is empty');
    $("#order_total").show();
    $('.submitorder').hide();
}
}

```

Thanks a lot for your help in advance!

Answer: 
Just use a jquery selector and loop through it.

```
$("input").change(function(){
    var counter = 0;
    $("input").each(function(){
        if($(this).val() != "" && $(this).val() != 0) counter++;
    });

    $("#order_total").html('Total Items:' + counter + '<br>' + 'Order Subtotal: ' + total);
});

```
```
if(total > 0){
    var counter = 0;  
    $("input[type=text]").each(function(){
    if($(this).val() != "" && $(this).val() != 0) counter++;
    });
    $("#order_total").html('Total Items:' + counter + '<br>' + 'Order Subtotal: ' + total);
    $("#order_total").show();
    $('.submitorder').show();
}
if(total == 0){
    $("#order_total").html('Your shopping basket is empty');
    $("#order_total").show();
    $('.submitorder').hide();
}

```