Associate
- Joined
- 13 Jul 2005
- Posts
- 738
- Location
- Brisbane
How do i add together the values of multiple text boxes and display the sum in another?
Cheers
Cheers
function add(sectionNum, numBoxes)
{
var sectionTotal = 0
for (i = 1; i <= numBoxes; i++)
{
var tBoxId = "g" + sectionNum + "a" + i;
// Uncomment to debug the section name
// alert(tBoxId);
var tBox = document.getElementById(tBoxId);
//alert(tBox.value);
sectionTotal = sectionTotal + Number(tBox.value);
}
// set the total for the section
var totalTxtBx = document.getElementById("total" + sectionNum);
totalTxtBx.value = sectionTotal;
}
<form id="Processor" name="Processor" method="post">
<select id="Prochange" name="Plist"
onchange="document.getElementById('g1a2').value=this[this.selectedIndex].value">
<option>Select Processor...</option>
<option value="70">3000+</option>
<option value="90">3500+</option>
<option value="120">3700+</option>
</select><br />
<input type="text" name="g1a2" id="g1a2" value="0" onKeyUp="javascript:add(1,8)"><br />
<input type="reset" value="Clear" /><br />
</form>
£ <input type="text" name="g1a1" id="g1a1" value="0" onKeyUp="javascript:add(1,8)"><br/>
£ <input type="text" name="g1a3" id="g1a3" value="0" onKeyUp="javascript:add(1,8)"><br/>
£ <input type="text" name="g1a4" id="g1a4" value="0" onKeyUp="javascript:add(1,8)"><br/>
£ <input type="text" name="g1a5" id="g1a5" value="0" onKeyUp="javascript:add(1,8)"><br/>
£ <input type="text" name="g1a6" id="g1a6" value="0" onKeyUp="javascript:add(1,8)"><br/>
£ <input type="text" name="g1a7" id="g1a7" value="0" onKeyUp="javascript:add(1,8)"><br/>
£ <input type="text" name="g1a8" id="g1a8" value="0" onKeyUp="javascript:add(1,8)"><br/><br/>
<b>Total</b> - £ <input type="text" name="total1" id="total1" value="0" readOnly="true">