How to Get Selected Radio Button Value in jQuery
In this article, we will explain to you how to get selected radio button value in jQuery. you can easily get the selected radio button value after the button click event.
In this example, we get selected radio button values using jQuery. the jQuery:checked selector in combination with the val() method to retrieve the value of the selected radio button.
So you can see below our example.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 | <!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <title>How to Get Selected Radio Button Value in jQuery - XpertPhp</title> <script src="https://code.jquery.com/jquery-3.5.1.min.js"></script> <script> $(document).ready(function(){ $("input[type='button']").click(function(){ var radioValueColor = $("input[name='rdoColor']:checked").val(); if(radioValueColor){ alert("Your color is a - " + radioValueColor); } }); }); </script> </head> <body> <h4>Please Choose your Color.</h4> <p> <label><input type="radio" name="rdoColor" value="red">Red</label> <label><input type="radio" name="rdoColor" value="black">Black</label> <label><input type="radio" name="rdoColor" value="green">Green</label> </p> <p><input type="button" value="Get Color"></p> </body> </html> |
Read Also
how to get textbox value in javascript
How To Remove Empty Object From JSON In JavaScript
Allow Only Numbers In Textbox Javascript Onkeypress
Please follow and like us: