xxxxxxxxxx
$("input[name=mygroup][value=" + value + "]").prop('checked', true);
xxxxxxxxxx
By LOVE
Here , name=Gender is the name attribute value of the radio button
$("input[name='Gender']: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
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
<script>
$(document).ready(function() {
// Attach click event handler to the button
$('#checkButton').on('click', function() {
// Get the value to check for (replace "option2" with your desired value)
var valueToCheck = 'option2';
// Loop through each radio option
$('input[type="radio"]').each(function() {
// Compare the current radio option's value with the value to check
if ($(this).val() === valueToCheck) {
// If there's a match, set the radio option as checked
$(this).prop('checked', true);
}
});
});
});
</script>
xxxxxxxxxx
$('#myForm input').on('change', function() {
alert($('input[name=radioName]:checked', '#myForm').val());
});