Solved

Need to calculate total amount from 3 select statements?

Posted on 2013-06-10
5
350 Views
Last Modified: 2013-06-15
Hi,
I would like to get the total values from the 3 select statements below and then calculate and display the total points as well as a percentage score in the total_score div?

What is the best way to do this?



<div class="inputname">Production</div>
<div class="inputfield">
 
        <select style="width:50px" name="upd_application[rate_production]" id="rate_production">
          	  <option value="0"  >0</option>
		  <option value="1"  >1</option>
		  <option value="2"  >2</option>
		  <option value="3"  >3</option>
		  <option value="4"  >4</option>
		  <option value="5"  >5</option>
		  <option value="6"  >6</option>
		  <option value="7"  >7</option>
		  <option value="8"  >8</option>
		  <option value="9"  >9</option>
		  <option value="10"  >10</option>

        </select>
</div>

<div class="inputname">Entertainment</div>
<div class="inputfield">
 
        <select style="width:50px" name="upd_application[rate_entertainment]" id="rate_entertainment">
          	  <option value="0"  >0</option>
		  <option value="1"  >1</option>
		  <option value="2"  >2</option>
		  <option value="3"  >3</option>
		  <option value="4"  >4</option>
		  <option value="5"  >5</option>
		  <option value="6"  >6</option>
		  <option value="7"  >7</option>
		  <option value="8"  >8</option>
		  <option value="9"  >9</option>
		  <option value="10"  >10</option>
        </select>
</div>

<div class="inputname">Commercial Potential</div>
<div class="inputfield">
 
        <select style="width:50px" name="upd_application[rate_commercial_potential]" id="rate_commercial_potential">
          	  <option value="0"  >0</option>
		  <option value="1"  >1</option>
		  <option value="2"  >2</option>
		  <option value="3"  >3</option>
		  <option value="4"  >4</option>
		  <option value="5"  >5</option>
		  <option value="6"  >6</option>
		  <option value="7"  >7</option>
		  <option value="8"  >8</option>
		  <option value="9"  >9</option>
		  <option value="10"  >10</option>
        </select>
</div>



<div class="inputfield" style="height:80px">
<div id="total_score"></div>
</div>

Open in new window

0
Comment
Question by:sabecs
[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
  • 2
5 Comments
 
LVL 42

Accepted Solution

by:
sedgwick earned 250 total points
ID: 39234043
	var total = parseInt($('#rate_production').val(),10) + parseInt($('#rate_entertainment').val(),10)+ parseInt($('#rate_commercial_potential').val(),10);
	var percentage = total/30*100;
	$("#total_score").text(total + " (%" + percentage + ")");

Open in new window

0
 
LVL 15

Assisted Solution

by:Jagadishwor Dulal
Jagadishwor Dulal earned 250 total points
ID: 39234047
Try this example:
<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8">
<title>Untitled Document</title>
<script src="jquery.min.js"></script>
<script type="text/javascript">
$(document).ready(function() {
	$("#Submit").click(function(){
		var val1=$("#rate_production").val();
		var val2=$("#rate_entertainment").val();
		var val3=$("#rate_commercial_potential").val();
		var total = parseFloat(val1)+parseFloat(val2)+parseFloat(val3);
		$('#total_score').text(total);
	});
});
</script>
</head>

<body>
<div class="inputname">Production</div>
<div class="inputfield">
 
  <select style="width:50px" name="rate_production" id="rate_production">
          	  <option value="0"  >0</option>
		  <option value="1"  >1</option>
		  <option value="2"  >2</option>
		  <option value="3"  >3</option>
		  <option value="4"  >4</option>
		  <option value="5"  >5</option>
		  <option value="6"  >6</option>
		  <option value="7"  >7</option>
		  <option value="8"  >8</option>
		  <option value="9"  >9</option>
		  <option value="10"  >10</option>

        </select>
</div>

<div class="inputname">Entertainment</div>
<div class="inputfield">
 
  <select style="width:50px" name="rate_entertainment" id="rate_entertainment">
          	  <option value="0"  >0</option>
		  <option value="1"  >1</option>
		  <option value="2"  >2</option>
		  <option value="3"  >3</option>
		  <option value="4"  >4</option>
		  <option value="5"  >5</option>
		  <option value="6"  >6</option>
		  <option value="7"  >7</option>
		  <option value="8"  >8</option>
		  <option value="9"  >9</option>
		  <option value="10"  >10</option>
        </select>
</div>

<div class="inputname">Commercial Potential</div>
<div class="inputfield">
 
  <select style="width:50px" name="rate_commercial_potential" id="rate_commercial_potential">
    <option value="0"  >0</option>
		  <option value="1"  >1</option>
		  <option value="2"  >2</option>
		  <option value="3"  >3</option>
		  <option value="4"  >4</option>
		  <option value="5"  >5</option>
		  <option value="6"  >6</option>
		  <option value="7"  >7</option>
		  <option value="8"  >8</option>
		  <option value="9"  >9</option>
		  <option value="10"  >10</option>
        </select>
</div>
<div class="inputfield">
  <input type="submit" name="Submit" id="Submit" value="Submit">
</div>
<div class="inputfield" style="height:80px"></div>
<div id="total_score"></div>
</body>
</html>

Open in new window

0
 
LVL 42

Expert Comment

by:sedgwick
ID: 39234269
@sabecs
you should have at least split the points cause i posted the correct answer first.
Moreover, @jagadishdulal didn't provide the 2nd requirement of the question which is the percentage score.
0

Featured Post

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

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

JavaScript can be used in a browser to change parts of a webpage dynamically. It begins with the following pattern: If condition W is true, do thing X to target Y after event Z. Below are some tips and tricks to help you get started with JavaScript …
This article discusses how to implement server side field validation and display customized error messages to the client.
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)

687 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