Help with calculating multiple totals
Our basketball officials chapter is implementing an on-line evaulation form and I have been asked to create the form. The form itself was not a real problem but the officials would like the form to automatically total the points in each Section (A thru F) and automatically total the six sections into a grand total.
Right now I simply have a number of defaults: points per item, Section total, Grand total and a 'warning" that they need to update the totals if they make any changes to the default values.
I thought could establish a variable for each section, perform a loop function to derive a total, then add the variables together for an overall total, but it doesn't seem to be working.
I'm copying just a portion of the code (for Section A and Section B) below, along with my attempt at creating "functions" (at the end of the code) to do the math. (Not observed is treated the same as a "0")
I'm probably missing something very simple but just don't see it. Any ideas on what I need to change?
Thank you for any help.
Code:
<html>
<head>
<title>Officials' Evaulation</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<link rel="shortcut icon" href="http://www.emailmeform.com/builder/favicon.ico" />
<link rel="stylesheet" type="text/css" href="http://www.emailmeform.com/builder/styles/dynamic.php?t=post" />
</head>
<body bgcolor="#FFFFFF">
<script type="text/javascript" src="http://www.emailmeform.com/builder/js/dynamic.php?t=post&t2=0"></script>
<div style="color:red;font-weight:bold;"></div>
<form id="emf-form" enctype="multipart/form-data" method="post" action="http://www.emailmeform.com/builder/form/489590">
<table style="text-align:left;" cellpadding="2" cellspacing="0" border="0" bgcolor="#FFFFFF">
<tr valign="top">
<td style="" align="left"><font face="Verdana" size="2" color="#000000"><b>Pants
- clean, pressed</b></font><span style="color:red;"><small></small></span></td>
<td style="">
<select id="element_8" name="element_8" class="validate[optional]" onchange="CheckA();">
<option value="0">0</option>
<option value="1"selected="selected">1</option>
</select>
<div style="padding-bottom:8px;color:#000000;"><small><font face="Verdana"></font></small></div>
</td>
</tr>
<tr valign="top">
<td style="" align="left"><font face="Verdana" size="2" color="#000000"><b>Shirt
- clean, pressed</b></font><span style="color:red;"><small></small></span></td>
<td style="">
<select id="element_9" name="element_9" class="validate[optional]" onchange="CheckA();">
<option value="0">0</option>
<option value="1"selected="selected">1</option>
</select>
<div style="padding-bottom:8px;color:#000000;"><small><font face="Verdana"></font></small></div>
</td>
</tr>
.
.
<tr valign="top">
<td style="" align="left"><font face="Verdana" size="2" color="#000000"><b>Books
/ captains' meeting</b></font><span style="color:red;"><small></small></span></td>
<td style="">
<select id="element_17" name="element_17" class="validate[optional]" onchange="CheckA();">
<option value="0">0</option>
<option value="1"selected="selected">1</option>
<option value="Not observed">Not observed</option>
</select>
<div style="padding-bottom:8px;color:#000000;"><small><font face="Verdana"></font></small></div>
</td>
</tr>
<tr valign="top">
<td style="" align="left"><font face="Verdana" size="2" color="#000000"><b>Total
Points Section A (Max 10) <br />
Verify Total!</b></font><span style="color:red;"><small>*</small></span></td>
<td style="">
<input id="element_18" name="element_18" class="validate[required,custom[onlyNumber]]" value="10" size="4" type="text" />
<div style="padding-bottom:8px;color:#000000;"><small><font face="Verdana">If
you changed any of the point values for the<br />
items above, please update the "Total Points"<br />
value as well.</font></small></div>
</td>
</tr>
<tr valign="top">
<td style="" align="left"><font face="Verdana" size="2" color="#000000"><b>Comments
Section A</b></font><span style="color:red;"><small></small></span></td>
<td style="">
<textarea id="element_19" name="element_19" cols="40" rows="4" class="validate[optional] "></textarea>
<div style="padding-bottom:8px;color:#000000;"><small><font face="Verdana"></font></small></div>
</td>
</tr>
<tr valign="top">
<td style="" align="left"><font face="Verdana" size="2" color="#000000"><b>Consistent
hustle - each play</b></font><span style="color:red;"><small></small></span></td>
<td style="">
<select id="element_20" name="element_20" class="validate[optional]" onchange="CheckB();">
<option value="5">5</option>
<option value="4">4</option>
<option value="3"selected="selected">3</option>
<option value="2">2</option>
<option value="1">1</option>
</select>
<div style="padding-bottom:8px;color:#000000;"><small><font face="Verdana"></font></small></div>
</td>
</tr>
<tr valign="top">
<td style="" align="left"><font face="Verdana" size="2" color="#000000"><b>Position
- Lead / Trail</b></font><span style="color:red;"><small></small></span></td>
<td style="">
<select id="element_21" name="element_21" class="validate[optional]" onchange="CheckB();">
<option value="5">5</option>
<option value="4">4</option>
<option value="3"selected="selected">3</option>
<option value="2">2</option>
<option value="1">1</option>
</select>
<div style="padding-bottom:8px;color:#000000;"><small><font face="Verdana"></font></small></div>
</td>
</tr>
.
.
<tr valign="top">
<td style="" align="left"><font face="Verdana" size="2" color="#000000"><b>Total
Points Section B (Max 20) <br />
Verify Total!</b></font><span style="color:red;"><small>*</small></span></td>
<td style="">
<input id="element_24" name="element_24" class="validate[required,custom[onlyNumber]]" value="12" size="4" type="text" />
<div style="padding-bottom:8px;color:#000000;"><small><font face="Verdana">If
you changed any of the point values for the<br />
items above, please update the "Total Points"<br />
value as well.</font></small></div>
</td>
</tr>
<tr valign="top">
<td style="" align="left"><font face="Verdana" size="2" color="#000000"><b>Total
Score (Max 100) <br />
Verify Total!</b></font><span style="color:red;"><small>*</small></span></td>
<td style="">
<input id="element_48" name="element_48" class="validate[required,custom[onlyNumber]]" value="64" size="5" type="text" />
<div style="padding-bottom:8px;color:#000000;"><small><font face="Verdana">If
you changed any of the point values for the<br />
items above, please update the "Total Points"<br />
value as well.</font></small></div>
</td>
</tr>
<tr valign="top">
<td style="" align="left"><font face="Verdana" size="2" color="#000000"><b>Comments
- Overall</b></font><span style="color:red;"><small></small></span></td>
<td style="">
<textarea id="element_49" name="element_49" cols="40" rows="4" class="validate[optional] "></textarea>
<div style="padding-bottom:8px;color:#000000;"><small><font face="Verdana"></font></small></div>
</td>
</tr>
<tr>
<td colspan="2" align="right">
<input name="element_counts" value="50" type="hidden" />
<input value="Submit Form" type="submit" / name="submit">
<input value="Clear Form" type="reset" / name="reset">
</td>
</tr>
</table>
</form>
<script type="text/javascript">
function CheckA()
{
var SecA = 0;
for (i=8; i<=17; i++ )
{
k="element_"+i;
SecA += document.getElemenyById(k).value;
return SecA
document.getElementById("element_18").value=SecA;
}
}
function CheckB()
{
var SecB = 0;
for (i=20; i<=23; i++ )
{
k="element_"+i;
SecB += document.getElementById(k).value;
document.getElementById("element_24").value=SecB;
}
}
function CheckTot()
{
var GTot = 0;
{
GTot== SecA + SecB + SecC + SecD + SecE + SecF};
document.getElementById("element_48").value=GTot;
}
</script>
</body>
</html>
Last edited by Kor; 10-25-2010 at 12:21 PM .
Reason: use [code] not [php], as you are not dealing with PHP
At a first glance:
the return command will stop the code in a function at that line. Everything below will not run at all. In a loop it acts as an "absolute" break .
Kor,
Thank you, but that line <return SecA> was added during my latest attempt at making the code work. It had not been there previously and should have been removed before I loaded the code. Even with the line removed, the code did not work as intended.
Post again your corrected code, then. And make clear what do you mean by :"but it doesn't seem to be working".
The issue is: how best to perform an automatic calculation of items selected within each Section of the form, leading to "Section" sub-totals in "element_18", "element_24", "element_30", "element_35", "element_40", and "element_46" as well as the automatic calulation of an overall total for "element_48".
As an alternative, we could get by with the automatic computation of just a single total from all the point values selected in the upper "Sections" of the form.
The functions (CheckA, CheckB, etc) called at the end of the code below do not perform the expected calculation.
The entire form has 50 "elements" and six "Sections" (A - F). So I'm posting the code for only a portion (or two) of the entire page.
Here is the (corrected) code posted previously in this thread:
Code:
<html>
<head>
<title>Officials' Evaulation</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<link rel="shortcut icon" href="http://www.emailmeform.com/builder/favicon.ico" />
<link rel="stylesheet" type="text/css" href="http://www.emailmeform.com/builder/styles/dynamic.php?t=post" />
</head>
<body bgcolor="#FFFFFF">
<script type="text/javascript" src="http://www.emailmeform.com/builder/js/dynamic.php?t=post&t2=0"></script>
<div style="color:red;font-weight:bold;"></div>
<form id="emf-form" enctype="multipart/form-data" method="post" action="http://www.emailmeform.com/builder/form/489590">
<table style="text-align:left;" cellpadding="2" cellspacing="0" border="0" bgcolor="#FFFFFF">
<tr valign="top">
<td style="" align="left"><font face="Verdana" size="2" color="#000000"><b>Pants
- clean, pressed</b></font><span style="color:red;"><small></small></span></td>
<td style="">
<select id="element_8" name="element_8" class="validate[optional]" onchange="CheckA();CheckTot();">
<option value="0">0</option>
<option value="1"selected="selected">1</option>
</select>
<div style="padding-bottom:8px;color:#000000;"><small><font face="Verdana"></font></small></div>
</td>
</tr>
<tr valign="top">
<td style="" align="left"><font face="Verdana" size="2" color="#000000"><b>Shirt
- clean, pressed</b></font><span style="color:red;"><small></small></span></td>
<td style="">
<select id="element_9" name="element_9" class="validate[optional]" onchange="CheckA();CheckTot();">
<option value="0">0</option>
<option value="1"selected="selected">1</option>
</select>
<div style="padding-bottom:8px;color:#000000;"><small><font face="Verdana"></font></small></div>
</td>
</tr>
.
.
<tr valign="top">
<td style="" align="left"><font face="Verdana" size="2" color="#000000"><b>Books
/ captains' meeting</b></font><span style="color:red;"><small></small></span></td>
<td style="">
<select id="element_17" name="element_17" class="validate[optional]" onchange="CheckA();CheckTot();">
<option value="0">0</option>
<option value="1"selected="selected">1</option>
<option value="Not observed">Not observed</option>
</select>
<div style="padding-bottom:8px;color:#000000;"><small><font face="Verdana"></font></small></div>
</td>
</tr>
<tr valign="top">
<td style="" align="left"><font face="Verdana" size="2" color="#000000"><b>Total
Points Section A (Max 10) <br />
Verify Total!</b></font><span style="color:red;"><small>*</small></span></td>
<td style="">
<input id="element_18" name="element_18" class="validate[required,custom[onlyNumber]]" value="10" size="4" type="text" />
<div style="padding-bottom:8px;color:#000000;"><small><font face="Verdana">If
you changed any of the point values for the<br />
items above, please update the "Total Points"<br />
value as well.</font></small></div>
</td>
</tr>
<tr valign="top">
<td style="" align="left"><font face="Verdana" size="2" color="#000000"><b>Comments
Section A</b></font><span style="color:red;"><small></small></span></td>
<td style="">
<textarea id="element_19" name="element_19" cols="40" rows="4" class="validate[optional] "></textarea>
<div style="padding-bottom:8px;color:#000000;"><small><font face="Verdana"></font></small></div>
</td>
</tr>
<tr valign="top">
<td style="" align="left"><font face="Verdana" size="2" color="#000000"><b>Consistent
hustle - each play</b></font><span style="color:red;"><small></small></span></td>
<td style="">
<select id="element_20" name="element_20" class="validate[optional]" onchange="CheckB();CheckTot();">
<option value="5">5</option>
<option value="4">4</option>
<option value="3"selected="selected">3</option>
<option value="2">2</option>
<option value="1">1</option>
</select>
<div style="padding-bottom:8px;color:#000000;"><small><font face="Verdana"></font></small></div>
</td>
</tr>
<tr valign="top">
<td style="" align="left"><font face="Verdana" size="2" color="#000000"><b>Position
- Lead / Trail</b></font><span style="color:red;"><small></small></span></td>
<td style="">
<select id="element_21" name="element_21" class="validate[optional]" onchange="CheckB();CheckTot();">
<option value="5">5</option>
<option value="4">4</option>
<option value="3"selected="selected">3</option>
<option value="2">2</option>
<option value="1">1</option>
</select>
<div style="padding-bottom:8px;color:#000000;"><small><font face="Verdana"></font></small></div>
</td>
</tr>
.
.
<tr valign="top">
<td style="" align="left"><font face="Verdana" size="2" color="#000000"><b>Total
Points Section B (Max 20) <br />
Verify Total!</b></font><span style="color:red;"><small>*</small></span></td>
<td style="">
<input id="element_24" name="element_24" class="validate[required,custom[onlyNumber]]" value="12" size="4" type="text" />
<div style="padding-bottom:8px;color:#000000;"><small><font face="Verdana">If
you changed any of the point values for the<br />
items above, please update the "Total Points"<br />
value as well.</font></small></div>
</td>
</tr>
<tr valign="top">
<td style="" align="left"><font face="Verdana" size="2" color="#000000"><b>Total
Score (Max 100) <br />
Verify Total!</b></font><span style="color:red;"><small>*</small></span></td>
<td style="">
<input id="element_48" name="element_48" class="validate[required,custom[onlyNumber]]" value="64" size="5" type="text" />
<div style="padding-bottom:8px;color:#000000;"><small><font face="Verdana">If
you changed any of the point values for the<br />
items above, please update the "Total Points"<br />
value as well.</font></small></div>
</td>
</tr>
<tr valign="top">
<td style="" align="left"><font face="Verdana" size="2" color="#000000"><b>Comments
- Overall</b></font><span style="color:red;"><small></small></span></td>
<td style="">
<textarea id="element_49" name="element_49" cols="40" rows="4" class="validate[optional] "></textarea>
<div style="padding-bottom:8px;color:#000000;"><small><font face="Verdana"></font></small></div>
</td>
</tr>
<tr>
<td colspan="2" align="right">
<input name="element_counts" value="50" type="hidden" />
<input value="Submit Form" type="submit" / name="submit">
<input value="Clear Form" type="reset" / name="reset">
</td>
</tr>
</table>
</form>
<script type="text/javascript">
function CheckA()
{
var SecA = 0;
for (i=8; i<=17; i++ )
{
k="element_"+i;
SecA += document.getElemenyById(k).value;
document.getElementById("element_18").value=SecA;
}
}
function CheckB()
{
var SecB = 0;
for (i=20; i<=23; i++ )
{
k="element_"+i;
SecB += document.getElementById(k).value;
document.getElementById("element_24").value=SecB;
}
}
function CheckTot()
{
var GTot = 0;
{
GTot== SecA + SecB + SecC + SecD + SecE + SecF};
document.getElementById("element_48").value=GTot;
}
</script>
</body>
</html>
Thread Information
Users Browsing this Thread
There are currently 1 users browsing this thread. (0 members and 1 guests)
Posting Permissions
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
Forum Rules
Bookmarks