Click here to Skip to main content
15,905,028 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
i have created two jsfiddle for row based calculation ,
here last two value are subtracted from first one.

eg: 10-2-6=2

for single row it works fine but i am getting problem for multiple rows

1: works fine as single row
http://jsfiddle.net/mishragaurav31/7Rt4D/5/[^]


2: i get problem with for loop
http://jsfiddle.net/mishragaurav31/JgcS2/[^]


kindly give what could be solution
Posted
Comments
Member 10434230 31-Jan-14 7:42am    
Is your problem resolved?

1 solution

JSFiddle: http://jsfiddle.net/JgcS2/25/[^]
HTML
Updated HTML:
<form  id="whereEntry" method='post' action=''>
<input type="text" class="income_count1" index="1" id="income1"> 
<input type="text" class="reduce_count1" index="1" id="income1" > 

<input type="text" class="reduce_count1" index="1" id="reduce1" > <br>

<input type="hidden" id="income_red1" >
<input type="hidden" id="income_sum1" > 
<br>
<input type="text" id="finale1" >

<br>
<hr>
<input type="text" class="income_count2" index="2" id="income2"> 
<input type="text" class="reduce_count2" index="2" id="income2" > 

<input type="text" class="reduce_count2" index="2" id="reduce2" > <br>

<input type="hidden" id="income_red2" >
<input type="hidden" id="income_sum2" > 
<br>
<input type="text" id="finale2" >

<br>
<hr>
</form>

Updated Script:
JavaScript
$( document ).ready(function() {                

for(var abc=1;abc<3;abc++)
{
    $('#whereEntry').delegate(".income_count"+abc, 'change', function ()
       {
           var incomeValue = $(this).val();
           var sum = 0;
           $('#whereEntry').find('.reduce_count'+$(this).attr('index')).each(function (){
               sum += Number($(this).val());
           });
         $('#finale'+$(this).attr('index')).val(incomeValue - sum);
    });


    $('#whereEntry').delegate(".reduce_count"+abc, 'change', function ()
{
   
    var incomeValue = $('#whereEntry').find('.income_count'+$(this).attr('index')).val();
    var sum = 0;
           $('#whereEntry').find('.reduce_count'+$(this).attr('index')).each(function (){
               sum += Number($(this).val());
           });
    $('#finale'+$(this).attr('index')).val(incomeValue - sum);                           
                                         
});

}     
    });
 
Share this answer
 
v4

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900