Posted By

sdxxx on 07/09/11


Tagged


Versions (?)

Calculate the sum of radio button values using jQuery


 / Published in: jQuery
 

URL: http://stackoverflow.com/questions/1324703/how-might-i-calculate-the-sum-of-radio-button-values-using-jquery

  1. <script>
  2. $("input[type=radio]").click(function() {
  3. var total = 0;
  4. $("input[type=radio]:checked").each(function() {
  5. total += parseFloat($(this).val());
  6. });
  7.  
  8. $(".totalSum").val(total);
  9. });
  10. </script>
  11.  
  12. <html>
  13. <body>
  14.  
  15. <input type="radio" value="15"/>
  16. <input type="radio" value="20"/>
  17. <input type="radio" value="30"/>
  18. <input class="totalSum" type="text"/>
  19.  
  20. </body>
  21. </html>

Report this snippet  

You need to login to post a comment.