Simple question.

You need to be more specific...

This for a website or application?

java/c/c#/c++/asp/php/perl/etc... ?
 
Cheers for the advice, one more thing though...

Code:
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;

}

Code:
<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">

How would i go about getting the Total amount to change once the drop down list changed the value in one of the text fields? Currently the Total amount only changes when the text fields are typed into.

Cheers
 
Basically you need to call the add function in the onchange event of the combo. But for some reason the function cant be called add and remain in the onchange event as it doesnt work must be a reserved name or something.

Code:
<html>

<head>

<script language="javascript">

function addnum(sectionNum, numBoxes) 
{
	alert("yay");

	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;

}

</script>

</head>

<body>

<form id="Processor" name="Processor" method="post">
	<select id="Prochange" name="Plist"
	onchange="document.getElementById('g1a2').value=this[this.selectedIndex].value; javascript:addnum(1,8);">
	<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"><br>
	<input type="reset" value="Clear" /><br />
</form>

	
£ <input type="text" name="g1a1" id="g1a1" value="0" onKeyUp="javascript:addnum(1,8)"><br/>
£ <input type="text" name="g1a3" id="g1a3" value="0" onKeyUp="javascript:addnum(1,8)"><br/>
£ <input type="text" name="g1a4" id="g1a4" value="0" onKeyUp="javascript:addnum(1,8)"><br/>
£ <input type="text" name="g1a5" id="g1a5" value="0" onKeyUp="javascript:addnum(1,8)"><br/>
£ <input type="text" name="g1a6" id="g1a6" value="0" onKeyUp="javascript:addnum(1,8)"><br/>
£ <input type="text" name="g1a7" id="g1a7" value="0" onKeyUp="javascript:addnum(1,8)"><br/>
£ <input type="text" name="g1a8" id="g1a8" value="0" onKeyUp="javascript:addnum(1,8)"><br/><br/>
<b>Total</b> - £ <input type="text" name="total1" id="total1" value="0" readOnly="true">

</body>
</html>
 
Back
Top Bottom