Well, as I understand, you have different input
fields and you want only those that have values != 0
. You can use this pseudo code which traverses thru all input
fields and your code will execute only if value != 0
:
$('input').each(function() {
if ($(this).val() != 0) {
// code goes here...
}
});
$('input').on('change', function() {
updateCount();
})
function updateCount() {
var count = 0;
$("input:not('.k-textbox')").each(function() {
if ($(this).val() != 0) {
count++;
}
});
$(".k-textbox").val(count + 'x');
console.log(count + 'x');
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<table border="1">
<tr>
<td>
<input type="text" name="total[]" id='total1' value="0" />
</td>
</tr>
<tr>
<td>
<input type="text" name="total[]" id='total2' value="0" />
</td>
</tr>
<tr>
<td>
<input type="text" name="total[]" id='total3' value="0" />
</td>
</tr>
<tr>
<td>
<input type="text" name="total[]" id='total4' value="0" />
</td>
</tr>
<tr>
<td>
<input type="text" class="k-textbox" value="" style="color: red; text-align: right; font-family: courier" name="total_amt_due" id="amt_due" readonly="readonly" />
</td>
</tr>
</table>
7
solved I have a form and i want to add all the is not equal to zero