This is my desired output. I want the date
will be equals to 1 and add in the total input and in class there's an additional x.
<div class="form-group{{ $errors->has('day1') ? ' has-error' : '' }}">
<label for="day1" class="col-md-4 control-label">Day 1</label>
<div class="col-md-6">
<div class='input-group date' id='day1'>
<input type='text' class="form-control" name="day1" value="0" readonly="readonly" />
<span class="input-group-addon">
<span class="glyphicon glyphicon-calendar">
</span>
</span>
</div>
</div>
</div>
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>