Jump to content

Updating total for change in row/column


smerny

Recommended Posts

i have this within a loop:

		<td><input type='text' id='p[".$i."]' name='p[".$i."]' value='".$_REQUEST['p'][$i]."' /></td>
	<td><input type='text' id='h[".$i."]' name='h[".$i."]' value='". $_REQUEST['h'][$i]."' /></td>
	<td><input type='text' id='m[".$i."]' name='m[".$i."]' value='".$_REQUEST['m'][$i]."' /></td>
	<td><input type='text' id='f[".$i."]' name='f[".$i."]' value='". $_REQUEST['f'][$i]."' /></td>
	<td><input type='text' id='c[".$i."]' name='c[".$i."]' value='".$_REQUEST['c'][$i]."' /></td>
	<td><span id='rowTotal[".$i."]'></span></td>

and then this after the loop:

<td><span id='pTotal'></span></td>
<td><span id='hTotal'></span></td>
<td><span id='mTotal'></span></td>
<td><span id='fTotal'></span></td>
<td><span id='cTotal'></span></td>
<td></td>

 

i want to put a "onBlur" for each of the inputs and have it update the row and column it's in, but i'm not sure how to deal with arrays like this and i'd like to do it without updating every single total... just the two (row and column of the modified cell)

Link to comment
https://forums.phpfreaks.com/topic/256695-updating-total-for-change-in-rowcolumn/
Share on other sites

nvm, got it with this (changed a few small things in the form code too):

 

function updateTotals(row, col)
{
updateRowTotal(row);
updateColTotal(col);
}
function updateColTotal(col)
{
var cTotal = 0;

for(i = 1; i <= gNumRealms; i++){
	cTotal += parseFloat(document.getElementById(col+'['+i+']').value);
}
document.getElementById(col+'[0]').value=cTotal;
}
function updateRowTotal(row)
{
var rTotal = 0;
rTotal += parseFloat(document.getElementById('p['+row+']').value);
rTotal += parseFloat(document.getElementById('h['+row+']').value);
rTotal += parseFloat(document.getElementById('m['+row+']').value);
rTotal += parseFloat(document.getElementById('f['+row+']').value);
rTotal += parseFloat(document.getElementById('c['+row+']').value);
rTotal = parseFloat(parseInt(rTotal*100))/100;
document.getElementById('rTotal['+row+']').innerHTML=rTotal;
}

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.