Click to See Complete Forum and Search --> : simple addition script but I can't get it!


needhelp
01-22-2003, 06:15 PM
I would love it if someone could tell me what I am doing wrong in this script. Also, in the function, what can I use after I get to Z? Can I use AA or lowercase a or a number? I have 30 questions in the poll.
If anyone knows an easier way to do this, that would be great too. Thanks for the help.

<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<SCRIPT language = JavaScript>

function calculate() {
A = eval(document.frmOne.txtOneNumber.value)
B = eval(document.frmOne.txtTwoNumber.value)
C = eval(document.frmOne.txtThreeNumber.value)
D = eval(document.frmOne.txtFourNumber.value)
E = eval(document.frmOne.txtFiveNumber.value)
F = eval(document.frmOne.txtSixNumber.value)
G = eval(document.frmOne.txtSevenNumber.value)
H = eval(document.frmOne.txtEightNumber.value)
I = eval(document.frmOne.txtNineNumber.value)
J = eval(document.frmOne.txtTenNumber.value)
K = eval(document.frmOne.txtElevenNumber.value)
L = eval(document.frmOne.txtTwelveNumber.value)
M = eval(document.frmOne.txtThirteenNumber.value)
N = eval(document.frmOne.txtForteenNumber.value)
O = eval(document.frmOne.txtFifthteenNumber.value)
P = eval(document.frmOne.txtSixteenNumber.value)
Q = eval(document.frmOne.txtSeventeenNumber.value)
R = eval(document.frmOne.txtEighteenNumber.value)
S = eval(document.frmOne.txtNinteenNumber.value)
T = eval(document.frmOne.txtTwentyNumber.value)
U = eval(document.frmOne.txtTwentyoneNumber.value)
V = eval(document.frmOne.txtTwentytwoNumber.value)
W = eval(document.frmOne.txtTwentythreeNumber.value)
X = eval(document.frmOne.txtTwentyfourNumber.value)
Y = eval(document.frmOne.txtTwentyfiveNumber.value)




Z = (A + B + C + D + E + F + G + H + I + J + K + L + M + N + O + P + Q + R + S + T + U + V + W + X + Y)
document.frmOne.txtScoreNumber.value = Z
}

</SCRIPT>


</head>

<body bgcolor="#FFFFFF">
<form name = frmOne>
<p>Type your response in the appropriate box. Your score will be calculated
at the end of the quiz.</p>
<p>1 = Never, 2 = Rarely, 3 = Usually, 4 = Always</p>
<table width="90%" border="3" cellspacing="0" cellpadding="5">
<tr>
<td width="493">1. Managers encourage and help develop employees' business
and/or personal goals. </td>
<td width="57">
<input type = Text name = txtOneNumber size = 1 value ="">
</td>
</tr>
<tr>
<td width="493">2. Employees can easily see their future inside the company.</td>
<td width="57">
<input type = Text name = txtTwoNumber size = 1 value ="">
</td>
</tr>
<tr>
<td width="493">3. All employees are aware of minimum behavior, activity,
and result standards.</td>
<td width="57">
<input type = Text name = txtThreeNumber size = 1 value ="">
</td>
</tr>
<tr>
<td width="493">4. If any employee is performing below minimal acceptable
standards, managers consistently take positive, appropriate and timely
action. </td>
<td width="57">
<input type = Text name = txtFourNumber size = 1 value ="">
</td>
</tr>
<tr>
<td width="493">5. Managers are aware of, knowledgeable of and supportive
of company processes, policies and procedures.</td>
<td width="57">
<input type = Text name = txtFiveNumber size = 1 value ="">
</td>
</tr>
<tr>
<td width="493">6. Employees understnad and support company policies and
procedures. </td>
<td width="57">
<input type = Text name = txtSixNumber size = 1 value ="">
</td>
</tr>
<tr>
<td width="493">7. Employees find their work environment challenging and
rewarding. </td>
<td width="57">
<input type = Text name = txtSevenNumber size = 1 value ="">
</td>
</tr>
<tr>
<td width="493">8. During challenges in the workplace, managers attempt
to turn difficulties into opportunities and make things better.</td>
<td width="57">
<input type = Text name = txtEightNumber size = 1 value ="">
</td>
</tr>
<tr>
<td width="493">9. Managers solcit constructive input from employees when
making departmental improvements.</td>
<td width="57">
<input type = Text name = txtNineNumber size = 1 value ="">
</td>
</tr>
<tr>
<td width="493">10. Managers are supportive of change and are always looking
to make things better.</td>
<td width="57">
<input type = Text name = txtTenNumber size = 1 value ="">
</td>
</tr>
<tr>
<td width="493">11. Managers regularly take time to talk to employees about
theings that are important to the employee.</td>
<td width="57">
<input type = Text name = txtElevenNumber size = 1 value ="">
</td>
</tr>
<tr>
<td width="493">12. Employees believe that managers tell them the &quot;whole&quot;
truth. </td>
<td width="57">
<input type = Text name = txtTwelveNumber size = 1 value ="">
</td>
</tr>
<tr>
<td width="493">13. Managers create and encourage teamwork that contributes
to company success.</td>
<td width="57">
<input type = Text name = txtThirteenNumber size = 1 value ="">
</td>
</tr>
<tr>
<td width="493">14. Managers encourage all departments and employees to
work together as a team.</td>
<td width="57">
<input type = Text name = txtForteenNumber size = 1 value ="">
</td>
</tr>
<tr>
<td width="493">15. In problem situations, managers expect employees to
take responsibility for planning, addressing, and resolving the issue.</td>
<td width="57">
<input type = Text name = txtFifteenNumber size = 1 value ="">
</td>
</tr>
<tr>
<td width="493">16. When employees work with managers, they gain confidence
and motivation to perform at higher levels.</td>
<td width="57">
<input type = Text name = txtSixteenNumber size = 1 value ="">
</td>
</tr>
<tr>
<td width="493">17. Employees respect their manager as a mentor, teacher
and coach.</td>
<td width="57">
<input type = Text name = txtSeventeenNumber size = 1 value ="">
</td>
</tr>
<tr>
<td width="493">18. Managers delegate responsibility in order to develop
the employee and the business.</td>
<td width="57">
<input type = Text name = txtEighteenNumber size = 1 value ="">
</td>
</tr>
<tr>
<td width="493">19. When making decisions, managers fucos on developing
people and building a team.</td>
<td width="57">
<input type = Text name = txtNineteenNumber size = 1 value ="">
</td>
</tr>
<tr>
<td width="493">20. Managers reference ongoing stragegic and tactical plans
when making decisions.</td>
<td width="57">
<input type = Text name = txtTwentyNumber size = 1 value ="">
</td>
</tr>
<tr>
<td width="493">21. Managers have a consistent recruiting plan.</td>
<td width="57">
<input type = Text name = txtTwentyoneNumber size = 1 value ="">
</td>
</tr>
<tr>
<td width="493">22. Managers use effective pre-developed interview questions
and make hiring decisions based on pre-established profiling and hiring
criteria. </td>
<td width="57">
<input type = Text name = txtTwentytwoNumber size = 1 value ="">
</td>
</tr>
<tr>
<td width="493">23. Managers consistently review priorities to determine
the most efficient use of their time.</td>
<td width="57">
<input type = Text name = txtTwentythreeNumber size = 1 value ="">
</td>
</tr>
<tr>
<td width="493">24. managers work to develo ptheir staff to perform their
job responsibilities better than the manager ever could.</td>
<td width="57">
<input type = Text name = txtTwentyfourNumber size = 1 value ="">
</td>
</tr>
<tr>
<td width="493">25. Managers help employees accept responsibility for their
own decisions/outcomes.</td>
<td width="57">
<input type = Text name = txtTwentyfiveNumber size = 1 value ="">
</td>
</tr>
<tr>
<td width="493">26. Managers attempt to understand individual employee motivations.
</td>
<td width="57">&nbsp; </td>
</tr>
<tr>
<td width="493">27. Managers know how to apply the right leadership competency,
at the right time, to the right situation.</td>
<td width="57">&nbsp; </td>
</tr>
<tr>
<td width="493">28. Managers have created plans and understand how to make
improvements with their team.</td>
<td width="57">&nbsp; </td>
</tr>
<tr>
<td width="493">29. Managers utilize a stragegic and tactical process for
generating future business and revenue opportunities.</td>
<td width="57">&nbsp; </td>
</tr>
<tr>
<td width="493">30. Managers understand, support and teach the company sales
process and model.</td>
<td width="57">&nbsp; </td>
</tr>
</table>
<p>
<input type = Button name = b1 value = "Calculate Score" onClick = calculate()>
</p>
<p> Total:
<input type = Text name = txtScoreNumber size = 8 value = "">
<p>&nbsp;
</form>
</body>
</html>

khalidali63
01-22-2003, 06:45 PM
Here you go my friend,
It should do the trick

cheers

Khalid


function calculate() {
var grandTotal = 0;
var frm = document.frmOne;
var len = frm.length;
for(x=0;x<len;x++){
if(frm[x].type=="text"){
var val = frm[x].value;
if(!isNaN(parseInt(val))){
grandTotal+=parseInt(val);
}
}
}
document.frmOne.txtScoreNumber.value = grandTotal;
}

Dan Drillich
01-23-2003, 09:33 AM
khalidali63,

Your code is neat!

One thing to be aware of is the fact that the grand total field is part of the form, so clicking on the button keeps summing up the 30 field values and the total.

One way to avoid it is by modifying the function calaculate -


function calculate() {
// initalize the total
document.frmOne.txtScoreNumber.value = 0;
var grandTotal = 0;
var frm = document.frmOne;
.......


Cheers,
Dan