View Single Post
  #7 (permalink)  
Old March 2nd, 2006, 10:46 AM
jayman jayman is offline
Authorized User
Join Date: Jan 2006
Location: , , .
Posts: 13
Thanks: 0
Thanked 0 Times in 0 Posts

Hi Chris,

I have a one page form with about 10 sets of text boxes on it.
At the end of each set of text boxes there is a box called Total score. Which should display the total score once data is input into the other text boxes.

I have this code so far that works:

function calculate(What) {
    for (var i=1,Total_Score1=0;i<3;i++)
       Total_Score1 += What.elements['Textfield' + i].value - 0;
    What.Total_Score1.value = Total_Score1;

This formula calculates the total score in a text box called Total Score1. Problem im having is that all the other text boxes are called some different e.g Total score1, Total score2 etc.

The other textfields that the user inputs scores into are called textfield1 etc. So that the formula adds up the scores no matter what u put in the text box.

How do i get the formula to calculate the total score for text boxes with the name of Total_score2,Total_score3 etc.


quote:Originally posted by ChrisScott
 Hi Jayman,

If you want to calculate the total client-side before posting, you can do this with client-side scripting.

Can you post the code for your form and your calculation requirements?