In this blog, you will learn how to know which radio button is selected in a form and what is its value using JQuery. You can use this while making registration form, or any other form which contain radio button.
To get the value of the selected radioName item of a form with id myForm:
1 |
$('input[name=radioName]:checked', '#myForm').val() |
With Example
1 2 3 4 |
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> $('#myForm input').on('change', function() { alert($('input[name=radioName]:checked', '#myForm').val()); }); |
1 2 3 |
<form id="myForm"><input name="radioName" type="radio" value="1" /> 1 <input name="radioName" type="radio" value="2" /> 2 <input name="radioName" type="radio" value="3" /> 3 </form> |
You May Also Like:
- Take Image Snapshot from a webcam with Jquery and HTML
- Create awesome book style preloader using CSS
- Pure CSS Animated Background
- How to decode JSON data and accessing the results in PHP
- Difference Between search() and indexOf() in Javascript
- Limit number of login attempt using PHP & MySQL
Thanks for reading, Keep reading Keep Visiting.