xxxxxxxxxx
$('input[name="name_of_your_radiobutton"]:checked').val();
xxxxxxxxxx
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<-- form input radio -->
<form id="myForm">
<input type="radio" name="radioName" value="1" /> 1 <br />
<input type="radio" name="radioName" value="2" /> 2 <br />
<input type="radio" name="radioName" value="3" /> 3 <br />
</form>
<script>
// function onclick
$("input[type='radio'][name='radioName']").click(function() {
var value = $(this).val();
});
// function onchange
$('#myForm input [type="radio"][name="radioName"]').on('change', function() {
alert($var value = $(this).val());
});
// get value by name
$("input[name='radioName']:checked").val()
// get value if has multiple form and get confuse which one will get
$('#myForm input[type=radio]:checked').val()
// another reference
$("input[type=radio][name='radioName']:checked").val()
</script>
xxxxxxxxxx
$('#myForm input').on('change', function() {
alert($('input[name=radioName]:checked', '#myForm').val());
});
xxxxxxxxxx
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<form id="myForm">
<input type="radio" name="radioName" value="1" /> 1 <br />
<input type="radio" name="radioName" value="2" /> 2 <br />
<input type="radio" name="radioName" value="3" /> 3 <br />
</form>
Run code snippetHide results