javascript - Adding AJAX forms inputs together, on user update -


update 3

james, mondaytotal, class in span tags, like,

    <span class="timebreakdowntotalweek">mon</span> <span class="mondaytotal">0</span> 

update 2

this function loads whole week, monday though sunday, , gives total. have tried, function changing '.totalhours' class mondaytotal, loads weekly total var. next add 'monday' before +count, seems add current rows monday mondaytotal class.

so example, have 3 rows with, '.monday0', '.monday1' , '.monday2'. monday total, hold total value, overrides when enter next value. enter 1 monday0, mondaytotal 1 when enter 2 monday1 instead of mondaytotal being 3, overrides , holds 2 - not add rows together.

i think due (at lest way see it, please correct me if wrong), 'index' each time resets 0 , not loop right.

 var loadhourtotals = function(count) {     if (typeof count === "undefined" ) {         var $total = $('.totalhours');         var $value = $('.input');     } else {         var $total = $('.'+count);         var $value = $('.'+count);     }      $value.on('input', function (e) {         var total = 0;         $value.each(function (index, elem) {             if (!number.isnan(parsefloat(this.value, 10))) total = total + parsefloat(this.value, 10);         });         $total.html(total);     }); } //end 

update

james, mean html form input into? if so, not easy, built using cakephp form helper, there code,

<input name="data[0][maintime]" class="timebreakdowninput monday0" type="text"> 

then when user clicks load form element, add,

<input name="data[1][maintime]" class="timebreakdowninput monday1" type="text"> 

then next, example,

<input name="data[2][maintime]" class="timebreakdowninput monday3" type="text"> 

then same other days. if not asking for, please explain more need,

thanks.


i working on form adds total number entered total week, giving weekly total. found function on post on here, , few changes want whole week.

but working on adding days, have total mondays, tuesdays etc. , grand total off week (but have not worked on let).

var loaddailytotal = function(count) {     var $weektotal = $('.mondaytotal');      if (typeof count === "undefined" ) {         var $weekvalue = $('.monday0');     } else {         var $weekvalue = $('.monday'+count);     }      $weekvalue.on('input', function(e) {         var totalweek = 0;         var currenttotal = parsefloat ($('.mondaytotal').html() );          $weekvalue.each(function (index, elem) {             if (!number.isnan(parsefloat(this.value, 10))) totalweek = totalweek + parsefloat(this.value, 10);         });         $weektotal.html(currenttotal + totalweek);     }); } 

right now, sort of works, don't think loop working right. 1 defult row loads, enter (for example) 1, add new ajax loaded row, , enter 2, make 3 in total. if update first row, 2, should 4 5, keeping total, don't want. need update total on each row, if , when user changes.

sorry if have not explained myself right, please give me change explain better, if needed or if want more code.

thanks,

if added class each day example select mondays add values.

<input name="data[0][maintime]" class="timebreakdowninput monday0 monday" type="text"> <input name="data[1][maintime]" class="timebreakdowninput monday1 monday" type="text"> <input name="data[2][maintime]" class="timebreakdowninput monday2 monday" type="text">  var getdaytotal = function(day){    var days=$('.'+day);    var total =0;    days.each(function(){        total+=parsefloat(this.value, 10);    });    return total; }  $('.mondaytotal').html(getdaytotal('monday')); 

Comments

Popular posts from this blog

javascript - RequestAnimationFrame not working when exiting fullscreen switching space on Safari -

Python ctypes access violation with const pointer arguments -