Advertisement

04.12.2007 at 10:17PM PDT, ID: 22509011
[x]
Attachment Details
[x]
The Solution Rating System

With so many solutions, how can you tell which solutions are most likely to help you and which ones are not? To provide you with a tool to use, we rate our solutions based on various elements that most accurately determine if a solution is a quality solution. To explain what factors affect the solution rating, here are the elements we take into consideration when formulating our solution rating.

  • The Grade of the Solution
  • The Zone Rank of the Expert Providing the Solution
  • The Number of Author and Expert Comments
  • The Number of Experts Contributing
  • The Feedback of the Community

Your Input Matters
Because of the way the system is set up, the most important variable in this equation is you. As a member of Experts Exchange, you are able to cast your vote on the quality of the solutions in regard to how complete, accurate, helpful and easy to understand each solution is. When you provide your feedback, each rating is adjusted accordingly. So, if you see a solution that has a poor rating that you think is a good solution, let us know by rating it. As you do, the rating will be adjusted and will become more accurate for other members of our site.

If you have any suggestions that you would like to make for our rating system, please ask a question in the Suggestions Zone of Community Support.

Thank you!

7.6

HTML form calculations to have seperate totals for seperate sections in one form

Asked by crystalwolf in PHP Scripting Language, JavaScript

Tags: , ,

Hi,
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) - eval(previouslySelectedRadioButton.value);
      // Save the current radio selection value.
      previouslySelectedRadioButton.value = eval(inputItem.value);
      // Add the current radio button selection value to the total.
      calculatedTotal.value = eval(calculatedTotal.value) + eval(inputItem.value);
    } else {   // Process check boxes.
      if (inputItem.checked == false) {   // Item was uncheck. Subtract item value from total.
          calculatedTotal.value = eval(calculatedTotal.value) - eval(inputItem.value);
      } else {   // Item was checked. Add the item value to the total.
          calculatedTotal.value = eval(calculatedTotal.value) + eval(inputItem.value);
      }
    }

    // Total value should never be less than 0.
    if (calculatedTotal.value < 0) {
      InitForm();
    }

    // Return total value.
    return(calculatedTotal.value);
  }
}


// This function initialzes all the form elements to default values.
function InitForm() {
  // Reset values on form.
  document.selectionForm.total.value='0';
  document.selectionForm.calculatedTotal.value=0;
  document.selectionForm.previouslySelectedRadioButton.value=0;

  // Set all checkboxes and radio buttons on form to unchecked.
  for (i=0; i < document.selectionForm.elements.length; i++) {
    if (document.selectionForm.elements[i].type == 'checkbox' | document.selectionForm.elements[i].type == 'radio') {
      document.selectionForm.elements[i].checked = false;
    }
  }
}

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.leveragetosucceed.com/get-help-now-assessment-2-draft.html

Thank you for any help you can give me on this issue.



Start Free Trial
[+][-]04.13.2007 at 12:08AM PDT, ID: 18903827

Assisted solutions are selected by the member who asked the question as a comment that contributed to their question's solution.

Start your 14-day free trial to view this Assisted Solution or ask the Experts your question.

 
[+][-]04.13.2007 at 12:09AM PDT, ID: 18903828

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 14-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]04.13.2007 at 07:54PM PDT, ID: 18909585

View this solution now by starting your 14-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zones: PHP Scripting Language, JavaScript
Tags: html, calculations, form
Sign Up Now!
Solution Provided By: stanscott2
Participating Experts: 2
Solution Grade: A
 
 
[+][-]06.04.2008 at 06:45AM PDT, ID: 21710008

Experts Exchange has a courteous staff of administrators who help members get the most out of the website by means of administrative comments like this one.

Start your 14-day free trial to view this Administrative Comment or ask the Experts your question.

 
[+][-]06.08.2008 at 07:20PM PDT, ID: 21740579

Experts Exchange has a courteous staff of administrators who help members get the most out of the website by means of administrative comments like this one.

Start your 14-day free trial to view this Administrative Comment or ask the Experts your question.

 
 
Loading Advertisement...
20081112-EE-VQP-43