How to calculate the sum of radio button values using jQuery ? Last Updated : 23 Jul, 2025 Comments Improve Suggest changes 1 Likes Like Report In this article, we will see how to calculate the sum of radio button values using jQuery. To add the values of radio buttons, we will use the addition arithmetic operator. Approach: First, we will use radio buttons to select two numbers i.e. number1 and number2. If the user clicks on the radio button value, then the user selects the value and gets this value by using the jQuery val() method and use the parseInt() method to convert the value into a number. After selecting both numbers values, the user clicks on the "Calculate Sum" button to calculate the sum of the selected radio button values. Example: In this example, we will use the above approach. HTML <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title> Calculate the sum of radio button values using jQuery </title> <script src= "https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"> </script> <style> h1, h3 { text-align: center; } .GFG { width: 350px; margin: 0 auto; } </style> </head> <body> <h1 style="color: green;"> GeeksforGeeks </h1> <h3> Calculate the sum of radio button values using jQuery </h3> <div class="GFG"> <p> <label for="num1">Select First Number: </label> <input type="radio" name="fnum" value="10">10 <input type="radio" name="fnum" value="20">20 <input type="radio" name="fnum" value="30">30 </p> <p> <label for="num1">Select Second Number: </label> <input type="radio" name="snum" value="10">10 <input type="radio" name="snum" value="20">20 <input type="radio" name="snum" value="30">30 </p> <button>Calculate Sum</button> <p class="res"></p> </div> <script> $(document).ready(function () { let fnum = 0, snum = 0; $('input[name="fnum"]').on("click", function () { fnum = parseInt($('input[name="fnum"]:checked').val()); }); $('input[name="snum"]').on("click", function () { snum = parseInt($('input[name="snum"]:checked').val()); }); $("button").on('click', function () { let sum = fnum + snum; $(".res").html("Sum of Two Numbers: " + sum); }); }); </script> </body> </html> Output: Create Quiz Comment V vkash8574 Follow 1 Improve V vkash8574 Follow 1 Improve Article Tags : HTML jQuery-Methods HTML-Questions jQuery-Questions Explore HTML BasicsHTML Introduction4 min readHTML Editors4 min readHTML Basics7 min readStructure & ElementsHTML Elements4 min readHTML Attributes7 min readHTML Headings3 min readHTML Paragraphs3 min readHTML Text Formatting4 min readHTML Block and Inline Elements3 min readHTML Charsets4 min readListsHTML Lists3 min readHTML Ordered Lists5 min readHTML Unordered Lists4 min readHTML Description Lists3 min readVisuals & MediaHTML Colors11 min readHTML Links Hyperlinks2 min readHTML Images7 min readHTML Favicon4 min readHTML Video4 min readLayouts & DesignsHTML Tables9 min readHTML Iframes4 min readHTML Layout4 min readHTML File Paths3 min readProjects & Advanced TopicsHTML Forms4 min readHTML5 Semantics5 min readHTML URL Encoding4 min readHTML Responsive Web Design11 min readTop 10 Projects For Beginners To Practice HTML and CSS Skills8 min readTutorial ReferencesHTML Tags - A to Z List5 min readHTML Attributes Complete Reference8 min readHTML Global Attributes5 min readHTML5 Complete Reference8 min readHTML5 MathML Complete Reference3 min readHTML DOM Complete Reference15+ min readHTML DOM Audio/Video Complete Reference2 min readSVG Element Complete Reference5 min readSVG Attribute Complete Reference8 min readSVG Property Complete Reference7 min readHTML Canvas Complete Reference4 min read Like