Calculation form with radio button problem

i need someone can help me to look my codes and tell me the errors

Page 1 of 1

9 Replies - 4694 Views - Last Post: 04 March 2009 - 08:57 PM

#1 shahrul  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 12
  • Joined: 11-February 09

Calculation form with radio button problem

Posted 03 March 2009 - 08:46 PM

/*
I try to calculate all the number based on selected radio button and display it in the textfield on the same page
can someone can tell me the errors and suggest how to make my calculation is right.
ty
*/
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<script language = "Javascript" type="text/javascript">

function calculateA() {

	
	
	var A = formC.GeneralPerformanace.value.checked;
	var B = formC.studentCooperation.value.checked;
	var C = formC.studentPunctuality.value.checked;
	var D = formC.studentInitiative.value.checked;
	var E = formC.studentKnowledge.value.checked;
	var F = formC.studentSkill.value.checked;
	var G = formC.studentCapability.value.checked;
	
	var H = A + B + C + D + E + F + G;
	formC.totalSectionA.value = H; 
	
}
</SCRIPT>

<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<style type="text/css">
<!--
body,td,th {
	font-family: Arial, Helvetica, sans-serif;
	font-size: 12px;
}
.style1 {color: #FFFFFF}
-->
</style></head>

<body>

<form name="formC" method="post" action="">

  <table width="786" border="0" align="center" cellpadding="1" cellspacing="0">
	<tr>
	  <td colspan="7" bgcolor="#3300FF"><span class="style1">Form C - Internship Field Evaluation Form </span></td>
	</tr>
	<tr>
	  <td colspan="7">&nbsp;</td>
	</tr>
	<tr>
	  <td colspan="7">Brief description of internship task(s) / project(s) assigned: </td>
	</tr>
	<tr>
	  <td colspan="7"><textarea name="assignTask" cols="100" id="assignTask"></textarea></td>
	</tr>
	<tr>
	  <td colspan="7">&nbsp;</td>
	</tr>
	<tr>
	  <td colspan="7">&nbsp;</td>
	</tr>
	<tr>
	  <td colspan="7">Instruction : Please complete this form using the scale below:</td>
	</tr>
	<tr>
	  <td colspan="7">&nbsp;</td>
	</tr>
	<tr>
	  <td colspan="7">1: Unsatisfactory  2: Less Satisfactory 3: Satisfactory 4: Good 5: Very Good </td>
	</tr>
	<tr>
	  <td colspan="7">&nbsp;</td>
	</tr>
	<tr>
	  <td colspan="7" bgcolor="#FFFF99">Section A: Company's Supervisor Comments. </td>
	</tr>
	<tr>
	  <td colspan="7">&nbsp;</td>
	</tr>
	<tr>
	  <td width="18">1.</td>
	  <td width="417">General Performance of the student during Training period </td>
	  <td width="54"><input name="GeneralPerformance" type="radio" value="1">
		1</td>
	  <td width="85"><input name="GeneralPerformance" type="radio" value="2">
		2</td>
	  <td width="76"><input name="GeneralPerformance" type="radio" value="3">
		3</td>
	  <td width="79"><input name="GeneralPerformance" type="radio" value="4">
		4</td>
	  <td width="43"><input name="GeneralPerformance" type="radio" value="5">
		5</td>
	</tr>
	<tr>
	  <td>2.</td>
	  <td colspan="6">Student's ability to fit into the working environment: </td>
	</tr>
	<tr>
	  <td>&nbsp;</td>
	  <td>a) Co-operation</td>
	  <td><input name="studentCooperation" type="radio" value="1">
1</td>
	  <td><input name="studentCooperation" type="radio" value="2">
2</td>
	  <td><input name="studentCooperation" type="radio" value="3">
3</td>
	  <td><input name="studentCooperation" type="radio" value="4">
4</td>
	  <td><input name="studentCooperation" type="radio" value="5">
5</td>
	</tr>
	<tr>
	  <td>&nbsp;</td>
	  <td>b) Punctuality </td>
	  <td><input name="studentPunctuality" type="radio" value="1">
1</td>
	  <td><input name="studentPunctuality" type="radio" value="2">
2</td>
	  <td><input name="studentPunctuality" type="radio" value="3">
3</td>
	  <td><input name="studentPunctuality" type="radio" value="4">
4</td>
	  <td><input name="studentPunctuality" type="radio" value="5">
5</td>
	</tr>
	<tr>
	  <td>&nbsp;</td>
	  <td>c) Initiative </td>
	  <td><input name="studentInitiative" type="radio" value="1">
1</td>
	  <td><input name="studentInitiative" type="radio" value="2">
2</td>
	  <td><input name="studentInitiative" type="radio" value="3">
3</td>
	  <td><input name="studentInitiative" type="radio" value="4">
4</td>
	  <td><input name="studentInitiative" type="radio" value="5">
5</td>
	</tr>
	<tr>
	  <td>&nbsp;</td>
	  <td>d) Knowledge </td>
	  <td><input name="studentKnowledge" type="radio" value="1">
1</td>
	  <td><input name="studentKnowledge" type="radio" value="2">
2</td>
	  <td><input name="studentKnowledge" type="radio" value="3">
3</td>
	  <td><input name="studentKnowledge" type="radio" value="4">
4</td>
	  <td><input name="studentKnowledge" type="radio" value="5">
5</td>
	</tr>
	<tr>
	  <td>&nbsp;</td>
	  <td>e) Skill </td>
	  <td><input name="studentSkill" type="radio" value="1">
1</td>
	  <td><input name="studentSkill" type="radio" value="2">
2</td>
	  <td><input name="studentSkill" type="radio" value="3">
3</td>
	  <td><input name="studentSkill" type="radio" value="4">
4</td>
	  <td><input name="studentSkill" type="radio" value="5">
5</td>
	</tr>
	<tr>
	  <td>3.</td>
	  <td>Student's capability to accomplish the assigned task </td>
	  <td><input name="studentCapability" type="radio" value="1">
1</td>
	  <td><input name="studentCapability" type="radio" value="2">
2</td>
	  <td><input name="studentCapability" type="radio" value="3">
3</td>
	  <td><input name="studentCapability" type="radio" value="4">
4</td>
	  <td><input name="studentCapability" type="radio" value="5">
5</td>
	</tr>
	<tr>
	  <td>&nbsp;</td>
	  <td>Total : </td>
	  <td><input name="totalSectionA" type="text" id="totalSectionA" size="4" READONLY></td>
	  <td>/35</td>
	  
	  <td><input name="CalculateA" type="submit" id="CalculateA" value="Calculate" onclick="calculateA()"></td>
	  <td>&nbsp;</td>
	  <td>&nbsp;</td>
	</tr>
	
	<tr>
	  <td colspan="7">
	  </td>
  </tr></table>
</form>
</body>
</html>
 


Is This A Good Question/Topic? 0
  • +

Replies To: Calculation form with radio button problem

#2 JMRKER  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 134
  • View blog
  • Posts: 868
  • Joined: 25-October 08

Re: Calculation form with radio button problem

Posted 03 March 2009 - 09:48 PM

Couple of problems:
1. Check your spelling of 'GeneralPerformance'
2. Cannot sum a 'checked' status
3. Cannot retrieve status of radio button with your statements
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">

<style type="text/css">
body,td,th {
	font-family: Arial, Helvetica, sans-serif;
	font-size: 12px;
}
.style1 {color: #FFFFFF}
</style>

<script language = "Javascript" type="text/javascript">
function getRBtnName(GrpName) {
  var sel = document.getElementsByName(GrpName);
  var fnd = -1;
  var str = '';
  for (var i=0; i<sel.length; i++) {
	if (sel[i].checked == true) { str = sel[i].value;  fnd = i; }
  }
//  return fnd;   // return option index of selection
// comment out next line if option index used in line above  
  return str;
} 

function calculateA() {
	var A = getRBtnName('GeneralPerformance') * 1;
	var B = getRBtnName('studentCooperation') * 1;
	var C = getRBtnName('studentPunctuality') * 1;
	var D = getRBtnName('studentInitiative') * 1;
	var E = getRBtnName('studentKnowledge') * 1;
	var F = getRBtnName('studentSkill') * 1;
	var G = getRBtnName('studentCapability') * 1;
   
	var H = A + B + C + D + E + F + G;
	document.formC.totalSectionA.value = H;
   
}
</SCRIPT>
</head>

<body>
<form name="formC" method="post" action="" onsubmit="return false">

  <table width="786" border="0" align="center" cellpadding="1" cellspacing="0">
	<tr>
	  <td colspan="7" bgcolor="#3300FF"><span class="style1">
	  Form C - Internship Field Evaluation Form </span></td>
	</tr>
	<tr>
	  <td colspan="7"> </td>
	</tr>
	<tr>
	  <td colspan="7">Brief description of internship task(s) / project(s) assigned: </td>
	</tr>
	<tr>
	  <td colspan="7"><textarea name="assignTask" cols="100" id="assignTask"></textarea></td>
	</tr>
	<tr>
	  <td colspan="7"> </td>
	</tr>
	<tr>
	  <td colspan="7"> </td>
	</tr>
	<tr>
	  <td colspan="7">Instruction : Please complete this form using the scale below:</td>
	</tr>
	<tr>
	  <td colspan="7"> </td>
	</tr>
	<tr>
	  <td colspan="7">1: Unsatisfactory  2: Less Satisfactory 3: Satisfactory 4: Good 5: Very Good </td>
	</tr>
	<tr>
	  <td colspan="7"> </td>
	</tr>
	<tr>
	  <td colspan="7" bgcolor="#FFFF99">Section A: Company's Supervisor Comments. </td>
	</tr>
	<tr>
	  <td colspan="7"> </td>
	</tr>
	<tr>
	  <td width="18">1.</td>
	  <td width="417">General Performance of the student during Training period </td>
	  <td width="54"><input name="GeneralPerformance" type="radio" value="1">1</td>
	  <td width="85"><input name="GeneralPerformance" type="radio" value="2">2</td>
	  <td width="76"><input name="GeneralPerformance" type="radio" value="3">3</td>
	  <td width="79"><input name="GeneralPerformance" type="radio" value="4">4</td>
	  <td width="43"><input name="GeneralPerformance" type="radio" value="5">5</td>
	</tr>
	<tr>
	  <td>2.</td>
	  <td colspan="6">Student's ability to fit into the working environment: </td>
	</tr>
	<tr>
	  <td> </td>
	  <td>a) Co-operation</td>
	  <td><input name="studentCooperation" type="radio" value="1">1</td>
	  <td><input name="studentCooperation" type="radio" value="2">2</td>
	  <td><input name="studentCooperation" type="radio" value="3">3</td>
	  <td><input name="studentCooperation" type="radio" value="4">4</td>
	  <td><input name="studentCooperation" type="radio" value="5">5</td>
	</tr>
	<tr>
	  <td> </td>
	  <td>b) Punctuality </td>
	  <td><input name="studentPunctuality" type="radio" value="1">1</td>
	  <td><input name="studentPunctuality" type="radio" value="2">2</td>
	  <td><input name="studentPunctuality" type="radio" value="3">3</td>
	  <td><input name="studentPunctuality" type="radio" value="4">4</td>
	  <td><input name="studentPunctuality" type="radio" value="5">5</td>
	</tr>
	<tr>
	  <td> </td>
	  <td>c) Initiative </td>
	  <td><input name="studentInitiative" type="radio" value="1">1</td>
	  <td><input name="studentInitiative" type="radio" value="2">2</td>
	  <td><input name="studentInitiative" type="radio" value="3">3</td>
	  <td><input name="studentInitiative" type="radio" value="4">4</td>
	  <td><input name="studentInitiative" type="radio" value="5">5</td>
	</tr>
	<tr>
	  <td> </td>
	  <td>d) Knowledge </td>
	  <td><input name="studentKnowledge" type="radio" value="1">1</td>
	  <td><input name="studentKnowledge" type="radio" value="2">2</td>
	  <td><input name="studentKnowledge" type="radio" value="3">3</td>
	  <td><input name="studentKnowledge" type="radio" value="4">4</td>
	  <td><input name="studentKnowledge" type="radio" value="5">5</td>
	</tr>
	<tr>
	  <td> </td>
	  <td>e) Skill </td>
	  <td><input name="studentSkill" type="radio" value="1">1</td>
	  <td><input name="studentSkill" type="radio" value="2">2</td>
	  <td><input name="studentSkill" type="radio" value="3">3</td>
	  <td><input name="studentSkill" type="radio" value="4">4</td>
	  <td><input name="studentSkill" type="radio" value="5">5</td>
	</tr>
	<tr>
	  <td>3.</td>
	  <td>Student's capability to accomplish the assigned task </td>
	  <td><input name="studentCapability" type="radio" value="1">1</td>
	  <td><input name="studentCapability" type="radio" value="2">2</td>
	  <td><input name="studentCapability" type="radio" value="3">3</td>
	  <td><input name="studentCapability" type="radio" value="4">4</td>
	  <td><input name="studentCapability" type="radio" value="5">5</td>
	</tr>
	<tr>
	  <td> </td>
	  <td>Total : </td>
	  <td><input name="totalSectionA" type="text"
		   id="totalSectionA" size="4" READONLY value=""></td>
	  <td>/35</td>
	 
	  <td><input name="CalculateA" type="submit" id="CalculateA"
		   value="Calculate" onclick="calculateA()"></td>
	  <td> </td>
	  <td> </td>
	</tr>
   
	<tr>
	  <td colspan="7">
	  </td>
  </tr></table>
</form>
</body>
</html>


:)
Was This Post Helpful? 1
  • +
  • -

#3 shahrul  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 12
  • Joined: 11-February 09

Re: Calculation form with radio button problem

Posted 03 March 2009 - 10:36 PM

hi, thanks for your help.

can i ask something?

if i want to add other calculation (same like coding above) like example i have 4 section (section A, section B, section C and section D) in one form, should i put all my codes (all section) in one form? or i need separate it into other form?
thanks for your help
:)
Was This Post Helpful? 0
  • +
  • -

#4 JMRKER  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 134
  • View blog
  • Posts: 868
  • Joined: 25-October 08

Re: Calculation form with radio button problem

Posted 04 March 2009 - 07:58 AM

I'm not sure I understand the question, but one form should suffice.

My assumption is that you want a different sum for another group of buttons.
If yes, then create var sum1 = 0; and then do formula as before for that summation.

If not, then post an example of what you are trying to accomplish.
Was This Post Helpful? 0
  • +
  • -

#5 shahrul  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 12
  • Joined: 11-February 09

Re: Calculation form with radio button problem

Posted 04 March 2009 - 07:30 PM

hi, thanks for your help and spend time with me.

i have already done all the calculation in my form in all section.
The problem now is how to retrieve all the calculated number in all section, i mean i have 4 section and each of section i use the calculation formula above and i need to add all the section in a form and show the final result of all sum of the section. can u help me to give some ideas to do this calculation?
Was This Post Helpful? 0
  • +
  • -

#6 JMRKER  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 134
  • View blog
  • Posts: 868
  • Joined: 25-October 08

Re: Calculation form with radio button problem

Posted 04 March 2009 - 07:43 PM

Can you show the modified code
or a link to a live site to review?
Was This Post Helpful? 0
  • +
  • -

#7 shahrul  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 12
  • Joined: 11-February 09

Re: Calculation form with radio button problem

Posted 04 March 2009 - 07:50 PM

/* This is my modified code.
i have 3 sections (Section A, Section B and Section C)
what i need is i want to sum all the sections and show the final result in Section D
i have already done it but it not add all the section results but it show the wrong output
can u help me please?
:)
*/

<script language = "Javascript" type="text/javascript">
function getRBtnName(GrpName) {

  var sel = document.getElementsByName(GrpName);
  var fnd = -1;
  var str = '';
  for (var i=0; i<sel.length; i++) {
	if (sel[i].checked == true) { str = sel[i].value;  fnd = i; }
  }
//  return fnd;   // return option index of selection
// comment out next line if option index used in line above  
  return str;
}

function calculateA() {
	var A = getRBtnName('GeneralPerformance') * 1;
	var B = getRBtnName('studentCooperation') * 1;
	var C = getRBtnName('studentPunctuality') * 1;
	var D = getRBtnName('studentInitiative') * 1;
	var E = getRBtnName('studentKnowledge') * 1;
	var F = getRBtnName('studentSkill') * 1;
	var G = getRBtnName('studentCapability') * 1;
   
	var H = A + B + C + D + E + F + G;
	document.formCA.totalSectionA.value = H;
}

function calculateB() {
	
	var I = getRBtnName('overallIntroduction') * 1;
	var J = getRBtnName('overallAnalysis') * 1;
	var K = getRBtnName('overallContent') * 1;
	var L = getRBtnName('overallOutput') * 1;
	var M = getRBtnName('overallUsage') * 1;
	var N = getRBtnName('overallRelevancy') * 1;
	var O = getRBtnName('overallConclusion') * 1;
	
	var P = I + J + K + L + M + N + O;
	document.formCA.totalSectionB.value = P;
	}

function calculateC() {

	var Q = getRBtnName('companyRemark') * 1;
	var R = getRBtnName('LecturerRemark') * 1;
	
	var S = Q + R;
	document.formCA.totalSectionC.value = S;
	}
	

function getValue() {
	
	returnvalue()
}
	function returnvalue() {
	
	var a = document.formCA.totalSectionA.value;
	var b = document.formCA.totalSectionB.value;
	var c = document.formCA.totalSectionC.value;
	
	
	var e = a + b + c;
	document.formCA.totalSectionD.value = e;
	
	var f = e * 0.25;
	document.formCA.totalPercent.value = f;
	return false;
	}
</SCRIPT>


Was This Post Helpful? 0
  • +
  • -

#8 JMRKER  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 134
  • View blog
  • Posts: 868
  • Joined: 25-October 08

Re: Calculation form with radio button problem

Posted 04 March 2009 - 08:07 PM

You only show the script.
Show the HTML parts as well as they go together to
create the final project.
Was This Post Helpful? 0
  • +
  • -

#9 shahrul  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 12
  • Joined: 11-February 09

Re: Calculation form with radio button problem

Posted 04 March 2009 - 08:15 PM

// This is my full html page. i hope u will understand how the calculation is calculated
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">

<style type="text/css">
body,td,th {
	font-family: Arial, Helvetica, sans-serif;
	font-size: 12px;
}
.style1 {color: #FFFFFF}
</style>

<script language = "Javascript" type="text/javascript">
function getRBtnName(GrpName) {

  var sel = document.getElementsByName(GrpName);
  var fnd = -1;
  var str = '';
  for (var i=0; i<sel.length; i++) {
	if (sel[i].checked == true) { str = sel[i].value;  fnd = i; }
  }
//  return fnd;   // return option index of selection
// comment out next line if option index used in line above  
  return str;
}

function calculateA() {
	var A = getRBtnName('GeneralPerformance') * 1;
	var B = getRBtnName('studentCooperation') * 1;
	var C = getRBtnName('studentPunctuality') * 1;
	var D = getRBtnName('studentInitiative') * 1;
	var E = getRBtnName('studentKnowledge') * 1;
	var F = getRBtnName('studentSkill') * 1;
	var G = getRBtnName('studentCapability') * 1;
   
	var H = A + B + C + D + E + F + G;
	document.formCA.totalSectionA.value = H;
}

function calculateB() {
	
	var I = getRBtnName('overallIntroduction') * 1;
	var J = getRBtnName('overallAnalysis') * 1;
	var K = getRBtnName('overallContent') * 1;
	var L = getRBtnName('overallOutput') * 1;
	var M = getRBtnName('overallUsage') * 1;
	var N = getRBtnName('overallRelevancy') * 1;
	var O = getRBtnName('overallConclusion') * 1;
	
	var P = I + J + K + L + M + N + O;
	document.formCA.totalSectionB.value = P;
	}

function calculateC() {

	var Q = getRBtnName('companyRemark') * 1;
	var R = getRBtnName('LecturerRemark') * 1;
	
	var S = Q + R;
	document.formCA.totalSectionC.value = S;
	}
	

function getValue(getFinalResult) {

	
	
	returnvalue()
}
	function returnvalue() {
	
	var a = document.formCA.totalSectionA.value 
	var b = document.formCA.totalSectionB.value  
	var c = document.formCA.totalSectionC.value 
	
	
	var e = a + b + c;
	document.formCA.totalSectionD.value = e;
	
	var f = e * 0.25;
	document.formCA.totalPercent.value = f;
	return false;
	}
</SCRIPT>
</head>

<body>
<form name="formCA" method="post" action="" onsubmit="return false">

  <table width="786" border="0" align="center" cellpadding="1" cellspacing="0">
	<tr>
	  <td colspan="7" bgcolor="#3300FF"><span class="style1">
	  Form C - Internship Field Evaluation Form </span></td>
	</tr>
	<tr>
	  <td colspan="7"> </td>
	</tr>
	<tr>
	  <td colspan="7">Brief description of internship task(s) / project(s) assigned: </td>
	</tr>
	<tr>
	  <td colspan="7"><textarea name="assignTask" cols="100" id="assignTask"></textarea></td>
	</tr>
	<tr>
	  <td colspan="7"> </td>
	</tr>
	<tr>
	  <td colspan="7"> </td>
	</tr>
	<tr>
	  <td colspan="7">Instruction : Please complete this form using the scale below:</td>
	</tr>
	<tr>
	  <td colspan="7"> </td>
	</tr>
	<tr>
	  <td colspan="7">1: Unsatisfactory  2: Less Satisfactory 3: Satisfactory 4: Good 5: Very Good </td>
	</tr>
	<tr>
	  <td colspan="7"> </td>
	</tr>
	<tr>
	  <td colspan="7" bgcolor="#FFFF99">Section A: Company's Supervisor Comments. </td>
	</tr>
	<tr>
	  <td colspan="7"> </td>
	</tr>
	<tr>
	  <td width="18">1.</td>
	  <td width="417">General Performance of the student during Training period </td>
	  <td width="54"><input name="GeneralPerformance" type="radio" value="1">1</td>
	  <td width="85"><input name="GeneralPerformance" type="radio" value="2">2</td>
	  <td width="76"><input name="GeneralPerformance" type="radio" value="3">3</td>
	  <td width="79"><input name="GeneralPerformance" type="radio" value="4">4</td>
	  <td width="43"><input name="GeneralPerformance" type="radio" value="5">5</td>
	</tr>
	<tr>
	  <td>2.</td>
	  <td colspan="6">Student's ability to fit into the working environment: </td>
	</tr>
	<tr>
	  <td> </td>
	  <td>a) Co-operation</td>
	  <td><input name="studentCooperation" type="radio" value="1">1</td>
	  <td><input name="studentCooperation" type="radio" value="2">2</td>
	  <td><input name="studentCooperation" type="radio" value="3">3</td>
	  <td><input name="studentCooperation" type="radio" value="4">4</td>
	  <td><input name="studentCooperation" type="radio" value="5">5</td>
	</tr>
	<tr>
	  <td> </td>
	  <td>b) Punctuality </td>
	  <td><input name="studentPunctuality" type="radio" value="1">1</td>
	  <td><input name="studentPunctuality" type="radio" value="2">2</td>
	  <td><input name="studentPunctuality" type="radio" value="3">3</td>
	  <td><input name="studentPunctuality" type="radio" value="4">4</td>
	  <td><input name="studentPunctuality" type="radio" value="5">5</td>
	</tr>
	<tr>
	  <td> </td>
	  <td>c) Initiative </td>
	  <td><input name="studentInitiative" type="radio" value="1">1</td>
	  <td><input name="studentInitiative" type="radio" value="2">2</td>
	  <td><input name="studentInitiative" type="radio" value="3">3</td>
	  <td><input name="studentInitiative" type="radio" value="4">4</td>
	  <td><input name="studentInitiative" type="radio" value="5">5</td>
	</tr>
	<tr>
	  <td> </td>
	  <td>d) Knowledge </td>
	  <td><input name="studentKnowledge" type="radio" value="1">1</td>
	  <td><input name="studentKnowledge" type="radio" value="2">2</td>
	  <td><input name="studentKnowledge" type="radio" value="3">3</td>
	  <td><input name="studentKnowledge" type="radio" value="4">4</td>
	  <td><input name="studentKnowledge" type="radio" value="5">5</td>
	</tr>
	<tr>
	  <td> </td>
	  <td>e) Skill </td>
	  <td><input name="studentSkill" type="radio" value="1">1</td>
	  <td><input name="studentSkill" type="radio" value="2">2</td>
	  <td><input name="studentSkill" type="radio" value="3">3</td>
	  <td><input name="studentSkill" type="radio" value="4">4</td>
	  <td><input name="studentSkill" type="radio" value="5">5</td>
	</tr>
	<tr>
	  <td>3.</td>
	  <td>Student's capability to accomplish the assigned task </td>
	  <td><input name="studentCapability" type="radio" value="1">1</td>
	  <td><input name="studentCapability" type="radio" value="2">2</td>
	  <td><input name="studentCapability" type="radio" value="3">3</td>
	  <td><input name="studentCapability" type="radio" value="4">4</td>
	  <td><input name="studentCapability" type="radio" value="5">5</td>
	</tr>
	<tr>
	  <td> </td>
	  <td>Total : </td>
	  <td><input name="totalSectionA" type="text"
		   id="totalSectionA" size="4" READONLY value=""></td>
	  <td>/35</td>
	 
	  <td><input name="CalculateA" type="submit" id="CalculateA"
		   value="Calculate" onclick="calculateA()"></td>
	  <td> </td>
	  <td> </td>
	</tr>
   
	<tr>
	  <td colspan="7">
	  </td>
  </tr></table>

	<table width="817" align="center">
	<tr>
	  <td colspan="7" bgcolor="#FFFF66">Section B: Student's Presentation/Briefing/Discussion on Project/Task/Job Assigned </td>
	</tr>
	<tr>
	  <td colspan="7">&nbsp;</td>
	</tr>
	<tr>
	  <td width="14">1.</td>
	  <td width="427">Overall evaluation of presentation/briefing/discussion: </td>
	  <td width="53">&nbsp;</td>
	  <td width="84">&nbsp;</td>
	  <td width="82">&nbsp;</td>
	  <td width="76">&nbsp;</td>
	  <td width="49">&nbsp;</td>
	</tr>
	<tr>
	  <td>&nbsp;</td>
	  <td>a) Introduction</td>
	  <td><input name="overallIntroduction" type="radio" value="1">
1</td>
	  <td><input name="overallIntroduction" type="radio" value="2">
2</td>
	  <td><input name="overallIntroduction" type="radio" value="3">
3</td>
	  <td><input name="overallIntroduction" type="radio" value="4">
4</td>
	  <td><input name="overallIntroduction" type="radio" value="5">
5</td>
	</tr>
	<tr>
	  <td>&nbsp;</td>
	  <td>b) Analysis </td>
	  <td><input name="overallAnalysis" type="radio" value="1">
1</td>
	  <td><input name="overallAnalysis" type="radio" value="2">
2</td>
	  <td><input name="overallAnalysis" type="radio" value="3">
3</td>
	  <td><input name="overallAnalysis" type="radio" value="4">
4</td>
	  <td><input name="overallAnalysis" type="radio" value="5">
5</td>
	</tr>
	<tr>
	  <td>&nbsp;</td>
	  <td>c) Content </td>
	  <td><input name="overallContent" type="radio" value="1">
1</td>
	  <td><input name="overallContent" type="radio" value="2">
2</td>
	  <td><input name="overallContent" type="radio" value="3">
3</td>
	  <td><input name="overallContent" type="radio" value="4">
4</td>
	  <td><input name="overallContent" type="radio" value="5">
5</td>
	</tr>
	<tr>
	  <td>&nbsp;</td>
	  <td>d) Output of Project/task/job </td>
	  <td><input name="overallOutput" type="radio" value="1">
1</td>
	  <td><input name="overallOutput" type="radio" value="2">
2</td>
	  <td><input name="overallOutput" type="radio" value="3">
3</td>
	  <td><input name="overallOutput" type="radio" value="4">
4</td>
	  <td><input name="overallOutput" type="radio" value="5">
5</td>
	</tr>
	<tr>
	  <td>&nbsp;</td>
	  <td>e) Usage of graph, chart, questionairre, etc </td>
	  <td><input name="overallUsage" type="radio" value="1">
1</td>
	  <td><input name="overallUsage" type="radio" value="2">
2</td>
	  <td><input name="overallUsage" type="radio" value="3">
3</td>
	  <td><input name="overallUsage" type="radio" value="4">
4</td>
	  <td><input name="overallUsage" type="radio" value="5">
5</td>
	</tr>
	<tr>
	  <td>&nbsp;</td>
	  <td>f) Relevancy of project/task/job to the course taken by the student. </td>
	  <td><input name="overallRelevancy" type="radio" value="1">
1</td>
	  <td><input name="overallRelevancy" type="radio" value="2">
2</td>
	  <td><input name="overallRelevancy" type="radio" value="3">
3</td>
	  <td><input name="overallRelevancy" type="radio" value="4">
4</td>
	  <td><input name="overallRelevancy" type="radio" value="5">
5</td>
	</tr>
	<tr>
	  <td>&nbsp;</td>
	  <td>g) Conclusion </td>
	  <td><input name="overallConclusion" type="radio" value="1">
1</td>
	  <td><input name="overallConclusion" type="radio" value="2">
2</td>
	  <td><input name="overallConclusion" type="radio" value="3">
3</td>
	  <td><input name="overallConclusion" type="radio" value="4">
4</td>
	  <td><input name="overallConclusion" type="radio" value="5">
5</td>
	</tr>
	<tr>
	  <td>&nbsp;</td>
	  <td>Total:</td>
	  <td><input name="totalSectionB" type="text" id="totalSectionB" size="4" READONLY value=""></td>
	  <td>/35</td>
	  <td><input type="submit" name="CalculateB" id="CalculateB" value="Calculate" onclick="calculateB()"></td>
	  <td>&nbsp;</td>
	  <td>&nbsp;</td>
	</tr>
	</table>
	
	<table width="814" align="center">
	<tr>
	  <td colspan="7">&nbsp;</td>
	</tr>
	<tr>
	  <td colspan="7" bgcolor="#FFFF99">Section C : Internal Supervisor Comments </td>
	</tr>
	<tr>
	  <td colspan="7">&nbsp;</td>
	</tr>
	<tr>
	  <td>1.</td>
	  <td>Company's remark on student (overall performance) </td>
	  <td><input name="companyRemark" type="radio" value="1">
1</td>
	  <td><input name="companyRemark" type="radio" value="2">
2</td>
	  <td><input name="companyRemark" type="radio" value="3">
3</td>
	  <td><input name="companyRemark" type="radio" value="4">
4</td>
	  <td><input name="companyRemark" type="radio" value="5">
5</td>
	</tr>
	<tr>
	  <td>2.</td>
	  <td>Internal supervisor's remark on student (overall performance) </td>
	  <td><input name="LecturerRemark" type="radio" value="1">
1</td>
	  <td><input name="LecturerRemark" type="radio" value="2">
2</td>
	  <td><input name="LecturerRemark" type="radio" value="3">
3</td>
	  <td><input name="LecturerRemark" type="radio" value="4">
4</td>
	  <td><input name="LecturerRemark" type="radio" value="5">
5</td>
	</tr>
	<tr>
	  <td>&nbsp;</td>
	  <td>Total:</td>
	  <td><input name="totalSectionC" type="text" id="totalSectionC" size="4" READONLY value=""></td>
	  <td>/10</td>
	  <td><input type="submit" name="CalculateC" id="CalculateC" value="Calculate" onclick="calculateC()"></td>
	  <td>&nbsp;</td>
	  <td>&nbsp;</td>
	</tr>
	<tr>
	  <td colspan="7">&nbsp;</td>
	</tr>
	<tr>
	  <td colspan="7" bgcolor="#FFFF99">Section D: Evaluation </td>
	</tr>
	<tr>
	  <td colspan="7">&nbsp;</td>
	</tr>
	<tr>
	  <td colspan="2">Total marks given for Field Evaluation = </td>
	  <td><input name="totalSectionD" type="text"id="totalSectionD" size="4" READONLY value=""></td>
	  <td>* 0.25 = </td>
	  <td><input name="totalPercent" type="text" id="totalPercent" size="4" READONLY value=""></td>
	  <td>/20%</td>
	  <td>&nbsp;</td>
	</tr>
	<tr>
	  <td>&nbsp;</td>
	  <td>&nbsp;</td>
	  <td>&nbsp;</td>
	  <td>&nbsp;</td>
	  <td><input name="calculateD" type="submit" id="calculateD" value="Calculate" onclick="getValue()"></td>
	  <td>&nbsp;</td>
	  <td>&nbsp;</td>
	</tr>
	<tr>
	  <td colspan="7">&nbsp;</td>
	</tr>
  </table>
	<p align="center">
	  <input type="submit" name="Submit" value="Submit">
  </p>
</form>
</body>
</html>


Was This Post Helpful? 0
  • +
  • -

#10 JMRKER  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 134
  • View blog
  • Posts: 868
  • Joined: 25-October 08

Re: Calculation form with radio button problem

Posted 04 March 2009 - 08:57 PM

You're not paying attention as to how to handle the math.
Strings in the text boxes need to be converted to numbers by the * 1
in order to be used in calculations correctly. This means all strings
that you are using as numbers (text and radion button option values).
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">

<style type="text/css">
body,td,th {
	font-family: Arial, Helvetica, sans-serif;
	font-size: 12px;
}
.style1 {color: #FFFFFF}
</style>

<script language = "Javascript" type="text/javascript">
function getRBtnName(GrpName) {

  var sel = document.getElementsByName(GrpName);
  var fnd = -1;
  var str = '';
  for (var i=0; i<sel.length; i++) {
	if (sel[i].checked == true) { str = sel[i].value;  fnd = i; }
  }
//  return fnd;   // return option index of selection
// comment out next line if option index used in line above  
  return str;
}

function calculateA() {
  var Agroup = ['GeneralPerformance','studentCooperation','studentPunctuality',
				'studentInitiative','studentKnowledge','studentSkill','studentCapability'];
  var sum = 0;
  for (var i=0; i<Agroup.length; i++) { sum += getRBtnName(Agroup[i]) * 1; }
  document.formCA.totalSectionA.value = sum;
}

function calculateB() {
  var Bgroup = ['overallIntroduction','overallAnalysis','overallContent',
				'overallOutput','overallUsage','overallRelevancy','overallConclusion'];
  var sum = 0;
  for (var i=0; i<Bgroup.length; i++) { sum += getRBtnName(Bgroup[i]) * 1; }
  document.formCA.totalSectionB.value = sum;
}

function calculateC() {
  var Cgroup = ['companyRemark','LecturerRemark'];
  var sum = 0;
  for (var i=0; i<Cgroup.length; i++) { sum += getRBtnName(Cgroup[i]) * 1; }
  document.formCA.totalSectionC.value = sum;
}
   

function getValue() {
	var a = document.formCA.totalSectionA.value * 1;
	var b = document.formCA.totalSectionB.value * 1;
	var c = document.formCA.totalSectionC.value * 1;
  
	document.formCA.totalSectionD.value = a + b + c;
	document.formCA.totalPercent.value = document.formCA.totalSectionD.value * 0.25;
}
</SCRIPT>
</head>

<body>
<form name="formCA" method="post" action="" onsubmit="return false">

  <table width="786" border="0" align="center" cellpadding="1" cellspacing="0">
	<tr>
	  <td colspan="7" bgcolor="#3300FF"><span class="style1">
	  Form C - Internship Field Evaluation Form </span></td>
	</tr>
	<tr>
	  <td colspan="7"> </td>
	</tr>
	<tr>
	  <td colspan="7">Brief description of internship task(s) / project(s) assigned: </td>
	</tr>
	<tr>
	  <td colspan="7"><textarea name="assignTask" cols="100" id="assignTask"></textarea></td>
	</tr>
	<tr>
	  <td colspan="7"> </td>
	</tr>
	<tr>
	  <td colspan="7"> </td>
	</tr>
	<tr>
	  <td colspan="7">Instruction : Please complete this form using the scale below:</td>
	</tr>
	<tr>
	  <td colspan="7"> </td>
	</tr>
	<tr>
	  <td colspan="7">1: Unsatisfactory  2: Less Satisfactory 3: Satisfactory 4: Good 5: Very Good </td>
	</tr>
	<tr>
	  <td colspan="7"> </td>
	</tr>
	<tr>
	  <td colspan="7" bgcolor="#FFFF99">Section A: Company's Supervisor Comments. </td>
	</tr>
	<tr>
	  <td colspan="7"> </td>
	</tr>
	<tr>
	  <td width="18">1.</td>
	  <td width="417">General Performance of the student during Training period </td>
	  <td width="54"><input name="GeneralPerformance" type="radio" value="1">1</td>
	  <td width="85"><input name="GeneralPerformance" type="radio" value="2">2</td>
	  <td width="76"><input name="GeneralPerformance" type="radio" value="3">3</td>
	  <td width="79"><input name="GeneralPerformance" type="radio" value="4">4</td>
	  <td width="43"><input name="GeneralPerformance" type="radio" value="5">5</td>
	</tr>
	<tr>
	  <td>2.</td>
	  <td colspan="6">Student's ability to fit into the working environment: </td>
	</tr>
	<tr>
	  <td> </td>
	  <td>a) Co-operation</td>
	  <td><input name="studentCooperation" type="radio" value="1">1</td>
	  <td><input name="studentCooperation" type="radio" value="2">2</td>
	  <td><input name="studentCooperation" type="radio" value="3">3</td>
	  <td><input name="studentCooperation" type="radio" value="4">4</td>
	  <td><input name="studentCooperation" type="radio" value="5">5</td>
	</tr>
	<tr>
	  <td> </td>
	  <td>b) Punctuality </td>
	  <td><input name="studentPunctuality" type="radio" value="1">1</td>
	  <td><input name="studentPunctuality" type="radio" value="2">2</td>
	  <td><input name="studentPunctuality" type="radio" value="3">3</td>
	  <td><input name="studentPunctuality" type="radio" value="4">4</td>
	  <td><input name="studentPunctuality" type="radio" value="5">5</td>
	</tr>
	<tr>
	  <td> </td>
	  <td>c) Initiative </td>
	  <td><input name="studentInitiative" type="radio" value="1">1</td>
	  <td><input name="studentInitiative" type="radio" value="2">2</td>
	  <td><input name="studentInitiative" type="radio" value="3">3</td>
	  <td><input name="studentInitiative" type="radio" value="4">4</td>
	  <td><input name="studentInitiative" type="radio" value="5">5</td>
	</tr>
	<tr>
	  <td> </td>
	  <td>d) Knowledge </td>
	  <td><input name="studentKnowledge" type="radio" value="1">1</td>
	  <td><input name="studentKnowledge" type="radio" value="2">2</td>
	  <td><input name="studentKnowledge" type="radio" value="3">3</td>
	  <td><input name="studentKnowledge" type="radio" value="4">4</td>
	  <td><input name="studentKnowledge" type="radio" value="5">5</td>
	</tr>
	<tr>
	  <td> </td>
	  <td>e) Skill </td>
	  <td><input name="studentSkill" type="radio" value="1">1</td>
	  <td><input name="studentSkill" type="radio" value="2">2</td>
	  <td><input name="studentSkill" type="radio" value="3">3</td>
	  <td><input name="studentSkill" type="radio" value="4">4</td>
	  <td><input name="studentSkill" type="radio" value="5">5</td>
	</tr>
	<tr>
	  <td>3.</td>
	  <td>Student's capability to accomplish the assigned task </td>
	  <td><input name="studentCapability" type="radio" value="1">1</td>
	  <td><input name="studentCapability" type="radio" value="2">2</td>
	  <td><input name="studentCapability" type="radio" value="3">3</td>
	  <td><input name="studentCapability" type="radio" value="4">4</td>
	  <td><input name="studentCapability" type="radio" value="5">5</td>
	</tr>
	<tr>
	  <td> </td>
	  <td>Total : </td>
	  <td><input name="totalSectionA" type="text"
		   id="totalSectionA" size="4" READONLY value=""></td>
	  <td>/35</td>
	 
	  <td><input name="CalculateA" type="submit" id="CalculateA"
		   value="Calculate" onclick="calculateA()"></td>
	  <td> </td>
	  <td> </td>
	</tr>
   
	<tr>
	  <td colspan="7">
	  </td>
  </tr></table>

	<table width="817" align="center">
	<tr>
	  <td colspan="7" bgcolor="#FFFF66">Section B: Student's Presentation/Briefing/Discussion on Project/Task/Job Assigned </td>
	</tr>
	<tr>
	  <td colspan="7"> </td>
	</tr>
	<tr>
	  <td width="14">1.</td>
	  <td width="427">Overall evaluation of presentation/briefing/discussion: </td>
	  <td width="53"> </td>
	  <td width="84"> </td>
	  <td width="82"> </td>
	  <td width="76"> </td>
	  <td width="49"> </td>
	</tr>
	<tr>
	  <td> </td>
	  <td>a) Introduction</td>
	  <td><input name="overallIntroduction" type="radio" value="1">1</td>
	  <td><input name="overallIntroduction" type="radio" value="2">2</td>
	  <td><input name="overallIntroduction" type="radio" value="3">3</td>
	  <td><input name="overallIntroduction" type="radio" value="4">4</td>
	  <td><input name="overallIntroduction" type="radio" value="5">5</td>
	</tr>
	<tr>
	  <td> </td>
	  <td>b) Analysis </td>
	  <td><input name="overallAnalysis" type="radio" value="1">1</td>
	  <td><input name="overallAnalysis" type="radio" value="2">2</td>
	  <td><input name="overallAnalysis" type="radio" value="3">3</td>
	  <td><input name="overallAnalysis" type="radio" value="4">4</td>
	  <td><input name="overallAnalysis" type="radio" value="5">5</td>
	</tr>
	<tr>
	  <td> </td>
	  <td>c) Content </td>
	  <td><input name="overallContent" type="radio" value="1">1</td>
	  <td><input name="overallContent" type="radio" value="2">2</td>
	  <td><input name="overallContent" type="radio" value="3">3</td>
	  <td><input name="overallContent" type="radio" value="4">4</td>
	  <td><input name="overallContent" type="radio" value="5">5</td>
	</tr>
	<tr>
	  <td> </td>
	  <td>d) Output of Project/task/job </td>
	  <td><input name="overallOutput" type="radio" value="1">1</td>
	  <td><input name="overallOutput" type="radio" value="2">2</td>
	  <td><input name="overallOutput" type="radio" value="3">3</td>
	  <td><input name="overallOutput" type="radio" value="4">4</td>
	  <td><input name="overallOutput" type="radio" value="5">5</td>
	</tr>
	<tr>
	  <td> </td>
	  <td>e) Usage of graph, chart, questionairre, etc </td>
	  <td><input name="overallUsage" type="radio" value="1">1</td>
	  <td><input name="overallUsage" type="radio" value="2">2</td>
	  <td><input name="overallUsage" type="radio" value="3">3</td>
	  <td><input name="overallUsage" type="radio" value="4">4</td>
	  <td><input name="overallUsage" type="radio" value="5">5</td>
	</tr>
	<tr>
	  <td> </td>
	  <td>f) Relevancy of project/task/job to the course taken by the student. </td>
	  <td><input name="overallRelevancy" type="radio" value="1">1</td>
	  <td><input name="overallRelevancy" type="radio" value="2">2</td>
	  <td><input name="overallRelevancy" type="radio" value="3">3</td>
	  <td><input name="overallRelevancy" type="radio" value="4">4</td>
	  <td><input name="overallRelevancy" type="radio" value="5">5</td>
	</tr>
	<tr>
	  <td> </td>
	  <td>g) Conclusion </td>
	  <td><input name="overallConclusion" type="radio" value="1">1</td>
	  <td><input name="overallConclusion" type="radio" value="2">2</td>
	  <td><input name="overallConclusion" type="radio" value="3">3</td>
	  <td><input name="overallConclusion" type="radio" value="4">4</td>
	  <td><input name="overallConclusion" type="radio" value="5">5</td>
	</tr>
	<tr>
	  <td> </td>
	  <td>Total:</td>
	  <td><input name="totalSectionB" type="text" id="totalSectionB" size="4" READONLY value=""></td>
	  <td>/35</td>
	  <td><input type="submit" name="CalculateB" id="CalculateB" value="Calculate" onclick="calculateB()"></td>
	  <td> </td>
	  <td> </td>
	</tr>
	</table>
   
	<table width="814" align="center">
	<tr>
	  <td colspan="7"> </td>
	</tr>
	<tr>
	  <td colspan="7" bgcolor="#FFFF99">Section C : Internal Supervisor Comments </td>
	</tr>
	<tr>
	  <td colspan="7"> </td>
	</tr>
	<tr>
	  <td>1.</td>
	  <td>Company's remark on student (overall performance) </td>
	  <td><input name="companyRemark" type="radio" value="1">1</td>
	  <td><input name="companyRemark" type="radio" value="2">2</td>
	  <td><input name="companyRemark" type="radio" value="3">3</td>
	  <td><input name="companyRemark" type="radio" value="4">4</td>
	  <td><input name="companyRemark" type="radio" value="5">5</td>
	</tr>
	<tr>
	  <td>2.</td>
	  <td>Internal supervisor's remark on student (overall performance) </td>
	  <td><input name="LecturerRemark" type="radio" value="1">1</td>
	  <td><input name="LecturerRemark" type="radio" value="2">2</td>
	  <td><input name="LecturerRemark" type="radio" value="3">3</td>
	  <td><input name="LecturerRemark" type="radio" value="4">4</td>
	  <td><input name="LecturerRemark" type="radio" value="5">5</td>
	</tr>
	<tr>
	  <td> </td>
	  <td>Total:</td>
	  <td><input name="totalSectionC" type="text"
		   id="totalSectionC" size="4" READONLY value=""></td>
	  <td>/10</td>
	  <td><input type="submit" name="CalculateC"
		   id="CalculateC" value="Calculate" onclick="calculateC()"></td>
	  <td> </td>
	  <td> </td>
	</tr>
	<tr>
	  <td colspan="7"> </td>
	</tr>
	<tr>
	  <td colspan="7" bgcolor="#FFFF99">Section D: Evaluation </td>
	</tr>
	<tr>
	  <td colspan="7"> </td>
	</tr>
	<tr>
	  <td colspan="2">Total marks given for Field Evaluation = </td>
	  <td><input name="totalSectionD" type="text"
		   id="totalSectionD" size="4" READONLY value=""></td>
	  <td>* 0.25 = </td>
	  <td><input name="totalPercent" type="text"
		   id="totalPercent" size="4" READONLY value=""></td>
	  <td>/20%</td>
	  <td> </td>
	</tr>
	<tr>
	  <td> </td>
	  <td> </td>
	  <td> </td>
	  <td> </td>
	  <td><input name="calculateD" type="submit"
		   id="calculateD" value="Calculate" onclick="getValue()"></td>
	  <td> </td>
	  <td> </td>
	</tr>
	<tr>
	  <td colspan="7"> </td>
	</tr>
  </table>
	<p align="center">
	  <input type="submit" name="Submit" value="Submit">
  </p>
</form>
</body>
</html>


Was This Post Helpful? 1
  • +
  • -

Page 1 of 1