javascript - Saving inputs to db after auto sum -
im trying save values input fields db after ive used js sum them up. want save both inputs , total sum , theres when code breaks down. inputs empty after autosum has run , sum of fields saved db. i'm not sure how fix this, im hoping out there have solution. here's code.
if stupid way of doing please show me right path!
<td> <div class="form-group"> {{ form::text('report_mon_time', input::old('report_mon_time'), array('name' => 'time', 'class' => 'form-control-s', 'onblur' => 'findtotaltime()')) }} </div> </td> <td> <div class="form-group"> {{ form::text('report_tue_time', input::old('report_tue_time'), array('name' => 'time', 'class' => 'form-control-s', 'onblur' => 'findtotaltime()')) }} </div> </td> <div class="form-group"> {{ form::text('report_tot_time', input::old('report_tot_time'), array('id' => 'tot_time','class' => 'form-control-s')) }} </div> <script> function findtotaltime(){ var number = document.getelementsbyname('time'); var arr = number; var tot=0; for(var i=0;i<arr.length;i++){ if(parseint(arr[i].value)) tot += parseint(arr[i].value); } document.getelementbyid('tot_time').value = tot; } </script>
change
for(var i=0;i<arr.length;i++){ for(var i=0;i<arr.length;i++){ if(parseint(arr[i].value)) tot += parseint(arr[i].value); }
to
for(var i=0;i<number.length;i++){ if(parseint(number[i].value)) tot += parseint(number[i].value); }
Comments
Post a Comment