Created
March 13, 2024 00:03
-
-
Save chrisegg/6a71ca4e8bb0ef6ab7f1f7889b47772e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Copy everything below this line | |
/** | |
* | |
* Conditionally Disable Radio Button Field | |
* | |
* This snippet disables a radio button field when a specific choice is selected in another radio button field. | |
* It will even clear the choice selection of the disabled field. | |
* See the link below for instructions. | |
* | |
* @Version: 1.0 | |
* @Author: Chris Eggleston | |
* @license: GPL-2.0+ | |
* @link: https://gravityranger.com/?p=33535 | |
* | |
*/ | |
<script> | |
jQuery(document).ready(function($){ | |
// Listen for changes on field 1 | |
$('fieldset#field_27_1 input[type="radio"]').change(function(){ | |
if($('fieldset#field_27_1 input[type="radio"]:checked').val() == '1'){ | |
// Disable field 4 and clear any selection if the specific value is selected in field 1 | |
$('fieldset#field_27_4 input').prop('disabled', true).prop('checked', false); | |
} else { | |
// Enable field 4 if the specific choice is not selected in field 1 | |
$('fieldset#field_27_4 input').prop('disabled', false); | |
} | |
}); | |
// Listen for changes on field 4 | |
$('fieldset#field_27_4 input[type="radio"]').change(function(){ | |
if($('fieldset#field_27_4 input[type="radio"]:checked').val() == '2'){ | |
// Disable field 1 and clear any selection if the specific value is selected in field 4 | |
$('fieldset#field_27_1 input').prop('disabled', true).prop('checked', false); | |
} else { | |
// Enable field 1 if the specific choice is not selected in field 4 | |
$('fieldset#field_27_1 input').prop('disabled', false); | |
} | |
}); | |
}); | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment