<div id="crm-radio-is_recur_radio-wrapper" class="crm-radio-wrapper crm-radio-wrapper-200px selected"><input class="" value="" type="radio" id="CRM_QFID_is_recur_radio" name="is_recur_radio"><label for="CRM_QFID_is_recur_radio">One-Time</label></div>
<input class="payment_processor_easy-pay crm-form-radio" value="4" type="radio" id="CRM_QFID_4_payment_processor_id" name="payment_processor_id">
<div id="crm-radio-is_recur_radio-wrapper" class="crm-radio-wrapper crm-radio-wrapper-200px"><input class="" value="month" type="radio" id="CRM_QFID_month_is_recur_radio" name="is_recur_radio"><label for="CRM_QFID_month_is_recur_radio">Monthly</label></div>
<input class="payment_processor_nach crm-form-radio" value="6" type="radio" id="CRM_QFID_6_payment_processor_id" name="payment_processor_id" checked="checked">
I have this 2 sets of button and I would like to automatically switch the radios. Condition is I can select only 1 radio.
For example when I select "CRM_QFID_is_recur_radio" button, "CRM_QFID_4_payment_processor_id" should be selected.
When I switch to CRM_QFID_month_is_recur_radio "CRM_QFID_6_payment_processor_id" should be selected.
How to do it in jquery? I have tried the following but it doesnt switch:
$('input[name=is_recur_radio]').change(function() {
$("input[name=is_recur_radio]:checked").attr("id") == "CRM_QFID_is_recur_radio" ? $('input[name=payment_processor_id][value=6]').prop("disabled", false) : $('input[name=payment_processor_id][value=6]').prop("disabled", true);
$("input[name=is_recur_radio]:checked").attr("id") == "CRM_QFID_month_is_recur_radio" ? $('input[name=payment_processor_id][value=4]').prop("disabled", true) : $('input[name=payment_processor_id][value=4]').prop("disabled", false);
$('input[name=payment_processor_id][value=6]').prop('checked', false);
$('input[name=payment_processor_id][value=4]').prop('checked', false);
});
2
Answers
If you have two radios:
You can use the following code to do whatever you want when one is checked:
To attempt to apply it to your situation:
If the accepted answer does what you need, then this is much DRYer
I gave the radios in the divs a class and use that to test
Let me know if the code below also works for you