[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

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

Posted on 2010-09-20
10
Medium Priority
?
458 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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
Learn how to optimize MySQL for your business need

With the increasing importance of apps & networks in both business & personal interconnections, perfor. has become one of the key metrics of successful communication. This ebook is a hands-on business-case-driven guide to understanding MySQL query parameter tuning & database perf

 
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

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

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

As with any other System Center product, the installation for the Authoring Tool can be quite a pain sometimes. This article serves to help you avoid making these mistakes and hopefully save you a ton of time on troubleshooting :)  Step 1: Make sur…
Deploying a Microsoft Access application in a Citrix environment is not difficult but takes a few steps. However, Citrix system people are often of little help, as they typically know next to nothing about Access. The script provided here will take …
The viewer will learn how to use the =DISCRINV command to create a discrete random variable, use this command to model a set of probabilities and outcomes in a Monte Carlo simulation, and learn how to find the standard deviation of a set of probabil…
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…

656 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