after all the second set of check boxes
then put this on all checkboxes ** ON ALL THE SECOND SET ONLY**
onclick="this.form.totalb.
like this
<input name="If_I_want_something_
Main Topics
Browse All TopicsHi,
I am in charge of setting up an assessment form for a website. This form has 2 sections where there are checkboxes that hold numeric values. These values must be added up at the end of each section.
(ie: Section 1: 10 questions - total of the 10 questions shown at the bottom of the section
Section 2: 12 questions - total of section 2 only shown at the bottom of the that section)
Then all form choices and totals to be submitted.
I have a PHP form handler submitting the information and currently I have a .js file processing the calculation in section 1 - but I have no idea how to differentiate the script to process the second calculation of section 2 without including section 1 in the calculations.
Here is the .js I am using as a separate file:
// Calculate the total for items in the form which are selected.
function calculateTotal(inputItem) {
with (inputItem.form) {
// Process each of the different input types in the form.
if (inputItem.type == "radio") { // Process radio buttons.
// Subtract the previously selected radio button value from the total.
calculatedTotal.value = eval(calculatedTotal.value
// Save the current radio selection value.
previouslySelectedRadioBut
// Add the current radio button selection value to the total.
calculatedTotal.value = eval(calculatedTotal.value
} else { // Process check boxes.
if (inputItem.checked == false) { // Item was uncheck. Subtract item value from total.
calculatedTotal.value = eval(calculatedTotal.value
} else { // Item was checked. Add the item value to the total.
calculatedTotal.value = eval(calculatedTotal.value
}
}
// Total value should never be less than 0.
if (calculatedTotal.value < 0) {
InitForm();
}
// Return total value.
return(calculatedTotal.val
}
}
// This function initialzes all the form elements to default values.
function InitForm() {
// Reset values on form.
document.selectionForm.tot
document.selectionForm.cal
document.selectionForm.pre
// Set all checkboxes and radio buttons on form to unchecked.
for (i=0; i < document.selectionForm.ele
if (document.selectionForm.el
document.selectionForm.ele
}
}
}
This script works, but produces an error-not sure why (I'm no genius where JS is concerned), but it calculates it and the total is submitted in the email which is great. Now I just need to figure how to do a separate one for section 2.
The HTML page is here - if you need the code:
http://www.leveragetosucce
Thank you for any help you can give me on this issue.
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
Let me suggest a simpler approach. Wrap each section of the form in span tags and deal with them separately:
<span id="section1">
<input...
<input...
<input...
</span>
<span id="section2">
<input...
<input...
<input...
</span>
Currently, you have a CalculateTotal routine that acts on an individual item. I would change this, so that CalculateTotal returns the total for a section, like this:
when I'm ready to get totals, I do this:
var total1 = calculateTotal("section1")
var total2 = calculateTotal("section2")
and the revised routine:
function calculateTotal(sp) {
var curSpan = document.getElementByid(sp
var allInputs = curSpan.getElementsByTagNa
var total = 0; // initialize
for (var t=0; t<allInputs.length; t++) {
var curInput = allInputs[t];
switch (curInput.type) {
case "radio":
if (curInput.selected) total += curInput.value;
break;
case "checkbox":
if (curInput.checked) total += curInput.value;
break;
case default: // or explicitly check for text type;
if (!isNaN(curInput.value)) total += curInput.value;
break;
}
}
return total;
}
You can now take the stored values in total1 and total2 and send them out for processing.
Business Accounts
Answer for Membership
by: wildzeroPosted on 2007-04-13 at 00:08:12ID: 18903827
From what I can see, do this
dioButtonb " value="0">
done" type="checkbox" value="2" onclick="this.form.totalb. value=calc ulateTotal b(this);">
{ e) - eval(previouslySelectedRad ioButton.v alue); tonb.value = eval(inputItem.value); e) + eval(inputItem.value); e) - eval(inputItem.value); e) + eval(inputItem.value);
lue);
al.value=' 0'; culatedTot al.value=0 ; viouslySel ectedRadio Button.val ue=0;
al.value=' 0'; culatedTot al.value=0 ; viouslySel ectedRadio Button.val ue=0; alb.value= '0'; culatedTot alb.value= 0; viouslySel ectedRadio Buttonb.va lue=0;
add a second field at the bottom of the page - this will be the result of the second lot of tick boxes.
Call it
do this :-)
<input type="hidden" name="calculatedTotalb" value="0">
<input type="hidden" name="previouslySelectedRa
<strong>Your total is:</strong>
<input type="text" name="totalb" readonly onfocus="this.blur();">
after all the second set of check boxes
then put this on all checkboxes
like this
<input name="If_I_want_something_
then in your javascript file add this
function calculateTotalb(inputItem)
with (inputItem.form) {
// Process each of the different input types in the form.
if (inputItem.type == "radio") { // Process radio buttons.
// Subtract the previously selected radio button value from the total.
calculatedTotalb.value = eval(calculatedTotalb.valu
// Save the current radio selection value.
previouslySelectedRadioBut
// Add the current radio button selection value to the total.
calculatedTotalb.value = eval(calculatedTotalb.valu
} else { // Process check boxes.
if (inputItem.checked == false) { // Item was uncheck. Subtract item value from total.
calculatedTotalb.value = eval(calculatedTotalb.valu
} else { // Item was checked. Add the item value to the total.
calculatedTotalb.value = eval(calculatedTotalb.valu
}
}
// Total value should never be less than 0.
if (calculatedTotalb.value < 0) {
InitForm();
}
// Return total value.
return(calculatedTotalb.va
}
}
and replace this
// Reset values on form.
document.selectionForm.tot
document.selectionForm.cal
document.selectionForm.pre
with this
// Reset values on form.
document.selectionForm.tot
document.selectionForm.cal
document.selectionForm.pre
document.selectionForm.tot
document.selectionForm.cal
document.selectionForm.pre
That should do it