Sebastian Mendoza Sebastian Mendoza - 3 years ago 62
jQuery Question

How can i assume that my date when has a value is equal to 1 and total?

The date if has value i want it equals to 1 and add it all in total

enter image description here

heres my sample fiddle My sample fiddle

html

$(document).ready(function(){
$('[id^=total]').on('change',function() {
var total = 0;

$('[id^=total]').each(function(index){

total += parseFloat($(this).val()?$(this).val():0);
});

var totalAll = $('#amt_due').val(total.toFixed(0));

});
});

Answer Source

I hope you want like this:-

$(document).ready(function(){ 
  var total = 0;
  $('input[type="date"]').on('change',function() {
    total +=1;
    $('#amt_due').val(total.toFixed(0));
  });
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<table border="1">
  <tr>
    <td>
      <input type='date' name='total[]' id='total1' value='' />
    </td>
  </tr>
  <tr>
    <td>
      <input type='date' name='total[]' id='total2' value='' />
    </td>
  </tr>
  <tr>
    <td>
      <input type='date' name='total[]' id='total3' value='' />
    </td>
  </tr>
  <tr>
    <td>
      <input type='date' name='total[]' id='total4' value='' />
    </td>
  </tr>
  <tr>
    <td>
      <input type='date' name='total[]' id='total5' value='' />
    </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>

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download