[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Compute the total of 3 textbox and put it in a different textbox

Posted on 2010-09-20
10
Medium Priority
?
460 Views
Last Modified: 2012-06-22
Please, bear with me, as this is my first time to do this. I just want to compute the average of the 3 textbox and put in a different textbox.

Evalgo Average Score should be computed as the average of the values of Evalgo Product Score, Evalgo Project Score and Evalgo Requirements Score. However, if any of the other 3 values is blank, do not include this in the computation. Samples below:

Sample 1            
Evalgo Product Score      3      
Evalgo Requirements Score      4      
Evalgo Project Score      5      
Evalgo Average Score      4      =(3+4+5)/3

Sample 2            
Evalgo Product Score      3      
Evalgo Requirements Score      4      
Evalgo Project Score             
Evalgo Average Score      3.5      =(3+4)/2

One more thing... the value of the Evalgo Average Score should be change or computed upon the textbox Onchange Event of  Evalgo Product Score, Evalgo Project Score and Evalgo Requirements Score.

9-20-2010-2-51-18-PM.png
0
Comment
Question by:PagodNaUtak
10 Comments
 
LVL 40

Expert Comment

by:Gurvinder Pal Singh
ID: 33714512
try this code

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
	<script>
		function score()
		{
			var averageScore = (getValue("EPdS") + getValue("EPjS") + getValue("ERS"))/3;
			document.getElementById("EAS").value = averageScore;
		}
		function getValue(id)
		{
			return parseInt(document.getElementById(id).value);
		}
	</script>
</HEAD>

<BODY BGCOLOR="#FFFFFF">
	Evalgo Product Score <input type="text" id="EPdS"\>
	Evalgo Project Score <input type="text" id="EPjS"\>
	<br>
	Evalgo Requirement Score <input type="text" id="ERS"\>
	Evalgo Average Score <input type="text" id="EAS"\>
	<br>
	<a href="javascript: score()">get average score</a>

</BODY>
</HTML>

Open in new window

0
 
LVL 8

Author Comment

by:PagodNaUtak
ID: 33714557
Hi! Thank you for your suggestion but there is something that is missing:
1) Please, see example number 2.
Sample 2            
Evalgo Product Score      3      
Evalgo Requirements Score      4      
Evalgo Project Score            
Evalgo Average Score      3.5      =(3+4)/2
 
0
 
LVL 75

Expert Comment

by:Michel Plungjan
ID: 33714571
Here
<script type="text/javascript">
function calc(theForm) {   
  var Evalgo_Product_Score      = theForm.EvalgoProductScore.value;     // 3
      Evalgo_Product_Score      = (Evalgo_Product_Score=="" || isNaN(Evalgo_Product_Score))?0:parseInt(Evalgo_Product_Score,10);
  var Evalgo_Requirements_Score = theForm.EvalgoRequirementsScore;      // 4
      Evalgo_Requirements_Score = (Evalgo_Requirements_Score=="" || isNaN(Evalgo_Requirements_Score))?0:parseInt(Evalgo_Requirements_Score,10);      
  var Evalgo_Project_Score      = theForm.EvalgoProjectScore.value;     // 5      
      Evalgo_Project_Score      = (Evalgo_Project_Score=="" || isNaN(Evalgo_Project_Score))?0:parseInt(Evalgo_Project_Score,10);
  theForm.EvalgoAverageScore.value = ((Evalgo_Product_Score+Evalgo_Requirements_Score+Evalgo_Project_Score)/3).toFixed(1);     // 4      =(3+4+5)/3
}
window.onload=function() {
  calc(document.forms[0])
}
</script>
<form>
EvalgoProductScore:        <input type="text" name="EvalgoProductScore"      value="" onKeyUp="calc(this.form)" /><br/>
EvalgoRequirementsScore:   <input type="text" name="EvalgoRequirementsScore" value="" onKeyUp="calc(this.form)" /><br/>
EvalgoProjectScore.value:  <input type="text" name="EvalgoProjectScore"      value="" onKeyUp="calc(this.form)" /><br/>      
Evalgo_Average_Score.value:<input type="text" name="EvalgoAverageScore"      value="" readonly="readonly" />
</form>

Open in new window

0
Granular recovery for Microsoft Exchange

With Veeam Explorer for Microsoft Exchange you can choose the Exchange Servers and restore points you’re interested in, and Veeam Explorer will present the contents of those mailbox stores for browsing, searching and exporting.

 
LVL 75

Accepted Solution

by:
Michel Plungjan earned 2000 total points
ID: 33714582
Aha. Sorry
better:

<script type="text/javascript">
function calc(theForm) {
  var divisor = 0;   
  var Evalgo_Product_Score      = theForm.EvalgoProductScore.value;     // 3
      Evalgo_Product_Score      = (Evalgo_Product_Score=="" || isNaN(Evalgo_Product_Score))?0:parseInt(Evalgo_Product_Score,10);
  if (Evalgo_Product_Score) divisor++;       
  var Evalgo_Requirements_Score = theForm.EvalgoRequirementsScore.value;      // 4
      Evalgo_Requirements_Score = (Evalgo_Requirements_Score=="" || isNaN(Evalgo_Requirements_Score))?0:parseInt(Evalgo_Requirements_Score,10);
  if (Evalgo_Requirements_Score) divisor++; 
  var Evalgo_Project_Score      = theForm.EvalgoProjectScore.value;     // 5      
      Evalgo_Project_Score      = (Evalgo_Project_Score=="" || isNaN(Evalgo_Project_Score))?0:parseInt(Evalgo_Project_Score,10);
  if (Evalgo_Project_Score) divisor++;
  theForm.EvalgoAverageScore.value = (divisor==0)?0:((Evalgo_Product_Score+Evalgo_Requirements_Score+Evalgo_Project_Score)/divisor).toFixed(1);     // 4      =(3+4+5)/3
}
window.onload=function() {
  calc(document.forms[0])
}
</script>
<form>
EvalgoProductScore:        <input type="text" name="EvalgoProductScore"      value="" onKeyUp="calc(this.form)" /><br/>
EvalgoRequirementsScore:   <input type="text" name="EvalgoRequirementsScore" value="" onKeyUp="calc(this.form)" /><br/>
EvalgoProjectScore.value:  <input type="text" name="EvalgoProjectScore"      value="" onKeyUp="calc(this.form)" /><br/>      
Evalgo_Average_Score.value:<input type="text" name="EvalgoAverageScore"      value="" readonly="readonly" />
</form>

Open in new window

0
 
LVL 40

Expert Comment

by:Gurvinder Pal Singh
ID: 33714616
try this

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
	<script>
		function score()
		{
			var totalScore = 0;
			var totalVars = 0;
			var val = getValue("EPdS");
			if ( val  )
			{
				totalScore += val;
				totalVars++;
			}
			val = getValue("EPjS");
			if ( val )
			{
				totalScore += val;
				totalVars++;
			}
			val = getValue("ERS");
			if ( val )
			{
				totalScore += val;
				totalVars++;
			}
			alert(totalScore);
			alert(totalVars);
			var averageScore = totalScore/totalVars;
			document.getElementById("EAS").value = averageScore;
		}
		function getValue(id)
		{
			var val = parseFloat(document.getElementById(id).value);
			return val;
		}
	</script>
</HEAD>

<BODY BGCOLOR="#FFFFFF">
	Evalgo Product Score <input type="text" id="EPdS"\>
	Evalgo Project Score <input type="text" id="EPjS"\>
	<br>
	Evalgo Requirement Score <input type="text" id="ERS"\>
	Evalgo Average Score <input type="text" id="EAS"\>
	<br>
	<a href="javascript: score()">get average score</a>

</BODY>
</HTML>

Open in new window

0
 
LVL 75

Expert Comment

by:Michel Plungjan
ID: 33714621
Ah. missed a .value

<script type="text/javascript">
function calc(theForm) {
  var divisor = 0;   
  var Evalgo_Product_Score      = theForm.EvalgoProductScore.value;     // 3
      Evalgo_Product_Score      = (Evalgo_Product_Score=="" || isNaN(Evalgo_Product_Score))?0:parseInt(Evalgo_Product_Score,10);
  if (Evalgo_Product_Score!=0) divisor++;
  var Evalgo_Requirements_Score = theForm.EvalgoRequirementsScore.value;      // 4
      Evalgo_Requirements_Score = (Evalgo_Requirements_Score=="" || isNaN(Evalgo_Requirements_Score))?0:parseInt(Evalgo_Requirements_Score,10);
  if (Evalgo_Requirements_Score!=0) divisor++;
  var Evalgo_Project_Score      = theForm.EvalgoProjectScore.value;     // 5      
      Evalgo_Project_Score      = (Evalgo_Project_Score=="" || isNaN(Evalgo_Project_Score))?0:parseInt(Evalgo_Project_Score,10);
  if (Evalgo_Project_Score!=0) divisor++;

  var total = Evalgo_Product_Score+Evalgo_Requirements_Score+Evalgo_Project_Score;
  var average = (divisor==0)?0:total/divisor;
  theForm.EvalgoAverageScore.value = average.toFixed(1);     // 4      =(3+4+5)/3
}
window.onload=function() {
  calc(document.forms[0])
}
</script>
<form>
EvalgoProductScore:        <input type="text" name="EvalgoProductScore"      value="" onKeyUp="calc(this.form)" /><br/>
EvalgoRequirementsScore:   <input type="text" name="EvalgoRequirementsScore" value="" onKeyUp="calc(this.form)" /><br/>
EvalgoProjectScore.value:  <input type="text" name="EvalgoProjectScore"      value="" onKeyUp="calc(this.form)" /><br/>      
Evalgo_Average_Score.value:<input type="text" name="EvalgoAverageScore"      value="" readonly="readonly" />
</form>

Open in new window

0
 
LVL 75

Expert Comment

by:Michel Plungjan
ID: 33714630
Gurvinder: You should have value on your fields and test for NaN
0
 
LVL 40

Expert Comment

by:Gurvinder Pal Singh
ID: 33714660
check line number 10, 16, and 22. the if condition is true only when it is not NaN.
0
 

Expert Comment

by:rcbcool
ID: 33715134
Check the below code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Test Document</title>
	<script>
		function score()
		{
			var fieldCount = 0;
			var valueTotal = 0;
			var valueAvg = 0;
			if(isNaN(getValue("EPdS")) == false){ fieldCount++; valueTotal += getValue("EPdS");};
			if(isNaN(getValue("EPjS")) == false){ fieldCount++; valueTotal += getValue("EPjS");};
			if(isNaN(getValue("ERS")) == false){ fieldCount++; valueTotal += getValue("ERS");};
			if(fieldCount > 0){
				valueAvg = (valueTotal)/fieldCount;
			}
			document.getElementById("EAS").value = valueAvg;
		}
		function getValue(id)
		{
			return parseInt(document.getElementById(id).value);
		}
	</script>
</head>

<BODY BGCOLOR="#FFFFFF">
	Evalgo Product Score <input type="text" id="EPdS"\>
	Evalgo Project Score <input type="text" id="EPjS"\>
	<br>
	Evalgo Requirement Score <input type="text" id="ERS"\>
	Evalgo Average Score <input type="text" id="EAS"\>
	<br>
	<a href="javascript: score()">get average score</a>
</body>
</html>

Open in new window

0
 
LVL 75

Expert Comment

by:Michel Plungjan
ID: 33715308
@rcbcool Welcome to EE, Please do not stitch together other people's suggestions and post as your own.
 
Thanks
0

Featured Post

Prepare for your VMware VCP6-DCV exam.

Josh Coen and Jason Langer have prepared the latest edition of VCP study guide. Both authors have been working in the IT field for more than a decade, and both hold VMware certifications. This 163-page guide covers all 10 of the exam blueprint sections.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article discusses how to implement server side field validation and display customized error messages to the client.
Ever visit a website where you spotted a really cool looking Font, yet couldn't figure out which font family it belonged to, or how to get a copy of it for your own use? This article explains the process of doing exactly that, as well as showing how…
The viewer will learn how to simulate a series of coin tosses with the rand() function and learn how to make these “tosses” depend on a predetermined probability. Flipping Coins in Excel: Enter =RAND() into cell A2: Recalculate the random variable…
The viewer will learn how to create a normally distributed random variable in Excel, use a normal distribution to simulate the return on an investment over a period of years, Create a Monte Carlo simulation using a normal random variable, and calcul…
Suggested Courses

829 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question