I want to get value selected radio button using jQuery
As you can see from my example, i select all radio box then sum it and put result into <p>
let total = 0; $('table input:radio:checked').each(function() { total += isNaN(parseInt($(this).val()))? 0: parseInt($(this).val()); }); $("p").html(total);
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script> <table> <tr> <td><input type='radio' value='1' checked>1</td> <td><input type='radio' value='2'>2</td> <td><input type='radio' value='3' checked>3</td> </tr> </table> total: <p></p>
let total = 0; let radios = document.querySelectorAll('table input[type="radio"]:checked'); radios.forEach((radio)=>{ total += isNaN(parseInt(radio.value))? 0: parseInt(radio.value); }); document.querySelector('p').innerHTML = total;
<table> <tr> <td><input type='radio' value='1' checked>1</td> <td><input type='radio' value='2'>2</td> <td><input type='radio' value='3' checked>3</td> </tr> </table> total: <p></p>
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.