# Checkbox Values calculation

**URL:** <https://forum.kirupa.com/t/checkbox-values-calculation/152381>\
**Category:** web dev\
**Created:** [June 24, 2005, 12:18pm UTC](https://forum.kirupa.com/t/checkbox-values-calculation/152381 "2005-06-24T12:18:26Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![scribbler](https://avatars.discourse-cdn.com/v4/letter/s/5fc32e/32.png) [@scribbler](https://forum.kirupa.com/u/scribbler)\
**Post date:** [June 24, 2005, 12:18pm UTC](https://forum.kirupa.com/t/checkbox-values-calculation/152381/1 "2005-06-24T12:18:26Z")

</div>

Can anyone please help me solve the following bearing in mind I’m a complete novice at javascript.

I saw a tutorial which calculated a value based upon whether or not a checkbox(s) value was selected/ticked. Each time the checkbox was checked or unchecked by a user the form re-cacluated the value. This works fine but now I’m trying to send the resulting information to another page where I can display only the selected items along with other information. I have listed the script that does the caculation each time the boxes are chekced/unchecked as I’d like to think the answer lies here.

\<script\>  
function calculate(inObj){  
//I Don’t need to pass inObj here since it is not used in the function  
BasicPrice=\<%=VehiclePricesRs(“BasicTotal”)%\>  
ttl = 0  
grandttl = 0  
//sets the total couter to 0  
allInput = document.getElementsByTagName(“input”)  
//loads all INPUT elements into an array called “allInput”  
for(x=0; x\<allInput.length; x++){  
//prepares to loop through the allInput array  
if (allInput[x].type == “checkbox”){  
//if the input type is a checkbox proceed  
if (allInput[x].checked){  
//if the checkbox is checked proceed  
val = parseFloat(allInput[x].value)  
//load the number value into a var called val  
if (!isNaN(val)) ttl += val  
//if val is a valid number (ie - not Not a Number) add it to the total  
}  
}  
}  
document.getElementById(“box4”).value = currency(ttl)  
document.getElementById(“box5”).value=currency(ttl +\<%=VehiclePricesRs(“BasicTotal”)%\>)  
//Now I write the total to an input with the ID box4 & box5  
}  
\</script\>
