smerny Posted February 8, 2012 Share Posted February 8, 2012 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) Quote Link to comment https://forums.phpfreaks.com/topic/256695-updating-total-for-change-in-rowcolumn/ Share on other sites More sharing options...
smerny Posted February 8, 2012 Author Share Posted February 8, 2012 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; } Quote Link to comment https://forums.phpfreaks.com/topic/256695-updating-total-for-change-in-rowcolumn/#findComment-1315984 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.