...

View Full Version : Resolved Getting the SUM of the values in Listbox



mikoto
05-28-2012, 01:48 PM
What i would like to happen is when i click the GET TOTAL button, i will be able to get the sum of all the values in the Amount List and display the sum in the Total: text box. Help please



<html><head><title>Charges Calculator</title>

<script language="javascript">
function addOption_all_list(selectbox){
removeAllOptions(document.form1.Category);
addOption(document.form1.Category, "110","110");
addOption(document.form1.Category, "99.99","99.99");
addOption(document.form1.Category, "19.99","19.99");
addOption(document.form1.Category, "8","8");
addOption(document.form1.Category, "5","5");
addOption(document.form1.Category, "6","6");

}

function addOption(selectbox,text,value )
{
var optn = document.createElement("OPTION");
optn.text = text;
optn.value = value;
selectbox.options.add(optn);
}

function removeOption(listbox,i)
{
listbox.remove(i);
}

function addOption_list(){
for(i=document.form1.Category.options.length-1;i>=0;i--) {
var Category=document.form1.Category;
if(document.form1.Category[i].selected){
addOption(document.form1.SubCat, document.form1.Category[i].value,

document.form1.Category[i].value);
removeOption(Category,i);
}
}
}
function move_all_Option(selectbox){
for(i=document.form1.Category.options.length-1;i>=0;i--) {
var Category=document.form1.Category;
addOption(document.form1.SubCat, document.form1.Category[i].value,

document.form1.Category[i].value);
}
removeAllOptions(document.form1.Category);
}



function removeAllOptions(selectbox)
{
var i;
for(i=selectbox.options.length-1;i>=0;i--)
{
//selectbox.options.remove(i);
selectbox.remove(i);
}
}

</script>

<script language="javascript" type="text/javascript">
function addition(){
a=Number(document.form1.SubCat.value);
b=Number(document.form1.SubCat.value);
c=a+b;
document.form1.total.value=c;
}

function deleteOption(selectObject,optionRank) {
if (selectObject.options.length!=0) { selectObject.options[optionRank]=null }
}

function testDelete() {
var formObject = document.form1
if (formObject.SubCat.selectedIndex!=-1) {
deleteOption(formObject.SubCat,formObject.SubCat.selectedIndex)
} else {
alert("Select an option and click Delete")
}
}
</script>

</head>

<body onload="addOption_all_list()"; >
<form name="form1" action="yourpage.php" method="post">
<input onclick="addOption_all_list()" ;="" value="Add All" type="button">
Rates:
<select name="Category" multiple="multiple" size="7">
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
<option value="5">5</option>
<option value="6">6</option>

</select>
&nbsp;

<input onclick="addOption_list()" ;="" value="Move" type="button">
<input onclick="move_all_Option()" ;="" value="Move All" type="button">
Amount List:
<select id="SubCat" name="SubCat" multiple="multiple" size="7">
</select>
<input type="button" value="Delete" onclick="testDelete();">
<input onclick="removeAllOptions(SubCat)" ;="" value="Reset" type="button">
<input type="button" value="Get Total" onclick="javascript:addition();"></br></br>
<br>Total:</br>
<input type="text" name="total">
</form>
</body>
</html>



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum