Jump to content

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;
}

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.