Calculate the sum of radio button values using jQuery


/ Published in: jQuery
Save to your folder(s)



Copy this code and paste it in your HTML
  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>

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

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.