Skip to content

Instantly share code, notes, and snippets.

@chrisegg
Created March 13, 2024 00:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chrisegg/6a71ca4e8bb0ef6ab7f1f7889b47772e to your computer and use it in GitHub Desktop.
Save chrisegg/6a71ca4e8bb0ef6ab7f1f7889b47772e to your computer and use it in GitHub Desktop.
//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