I have a checkbox list which contains 6 checkboxes. A corresponding radio button is placed beside each checkbox. When page load, the radio buttons are disabled. When I check the checkbox, I want to enable the radio button beside it. Furthermore, if I uncheck the checkboxes, the radio button beside it will be deselected and disabled again.
The checkbox is for the user to choose items they want, and the radio button is for the user to pick his favourite item.
I have tried this code below but it is not working...
$(document).ready(function () {
$("#rbtnlLeadAgencies input[type='radio']").each(function () {
$("#rbtnlLeadAgencies input[type='radio']").prop('disabled', true);
});
$("#cbxlAgencies input[type='checkbox']").each.change(function () {
if ($("#cbxlAgencies_0 input[type='checkbox']").is(':checked')) $("#rbtnlLeadAgencies_0 input[type='radio']").prop('disabled', false);
if ($("#cbxlAgencies_1 input[type='checkbox']").is(':checked')) $("#rbtnlLeadAgencies_1 input[type='radio']").prop('disabled', false);
if ($("#cbxlAgencies_2 input[type='checkbox']").is(':checked')) $("#rbtnlLeadAgencies_2 input[type='radio']").prop('disabled', false);
if ($("#cbxlAgencies_3 input[type='checkbox']").is(':checked')) $("#rbtnlLeadAgencies_3 input[type='radio']").prop('disabled', false);
if ($("#cbxlAgencies_4 input[type='checkbox']").is(':checked')) $("#rbtnlLeadAgencies_4 input[type='radio']").prop('disabled', false);
if ($("#cbxlAgencies_5 input[type='checkbox']").is(':checked')) $("#rbtnlLeadAgencies_5 input[type='radio']").prop('disabled', false);
});
});
The markups and jQuery code are on jsfiddle
Any ideas of achieving this behavior?
Thanks in advance!
data-for-radio="rbtnlLeadAgencies_3"
in your html and add a onchange event on checkbox to modify associated radio. faster and explicit id link. – TecHunter