Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

javascript checkbox frustration

Status
Not open for further replies.

scribbler

MIS
Feb 4, 2002
206
GB
After initial help from BillyRayPreachersSon who solved my original problem Can anyone please help me solve the following bearing in mind I'm a 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 after searching for answers I'm back to see if teh Tek-Tips forum can help.

I'm trying to send the resulting information of just the checked checkboxes to another page where I can display only the selected items along with other information from my form. I have listed the script that does the caculation each time the boxes are checked/unchecked as I think the answer lies here.

My checkboxes are variable in quantity between 1-70 but I have numbered each one in a variable called "Checkbox" & i (i being a counter matching the number of boxes)


<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>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top