[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 355
  • Last Modified:

Need to calculate total amount from 3 select statements?

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
sabecs
Asked:
sabecs
  • 2
2 Solutions
 
Meir RivkinFull stack Software EngineerCommented:
	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
 
Jagadishwor DulalBraces MediaCommented:
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
 
Meir RivkinFull stack Software EngineerCommented:
@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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now