You are viewing limited content. For full access, please sign in.



Disable (or hide) one radio button based on single line field value

asked on September 22, 2022

I'm trying to disable or hide one radio buttons based on the value in a single line field. That field (License Flag) is populated with the result of a formula based on information from a lookup ("Y" or "N"). If this field is "N", I'd like to disable or hide the Reject button:

After reading through many posts, I've been fiddling around with this, but I have been unsuccessful:

$(document).ready(function() {
    $("#q245" input).on("change", function(){
        if($(this).val() === "N"){
            $('.approverDecision input[value="Reject"]').prop('disabled', true);
            $('.approverDecision input[value="Reject"]').prop('disabled', false);

Suggestions appreciated. Thank you.

0 0


replied on September 22, 2022 Show version history

You have misplaced quotes on your selector.

You have "#q245" input

but it should be "#q245 input"

In addition, you can simplify your code by using the true/false of your condition directly when you set the state rather than using if/else statements with repetitive code.

Lastly, you should also make sure you clear the checked state. If for some reason the Reject option was selected, you wouldn't want it to stay selected once it is disabled.

$(document).ready(function() {
    $('#q245 input').on('change', function(){
        $('.approverDecision input[value="Reject"]').prop('checked', false)
                                                    .prop('disabled', $(this).val() === "N");

On a side note, you should always try to use the browser dev console to narrow down any issues when you are testing out JavaScript.

For example, if you right-click the page and choose Inspect, then go to the console tab, the issue with the quotes would be throwing an error.

2 0
replied on September 22, 2022

Thank you, Jason.

0 0


You are not allowed to reply in this post.
You are not allowed to follow up in this post.

Sign in to reply to this post.