Have an idea?

Visit Sawtooth Software Feedback to share your ideas on how we can improve our products.

Remove Checkbox / Radio button for multiple and single select on same page

<a href="https://legacy.sawtoothsoftware.com/forum/30922/remove-radio-button-on-single-select">I found this solution</a> which mostly works, but I have a multiple select question and a single select question.

The multi-select question is first and using this code works:
<style>
#[% QuestionName() %]_div .input_cell {
    display: none;
}
 
.selectedImg {
    border: 1px solid blue;
}
</style>
 
<script>
$(document).ready(SSI_CustomGraphicalCheckbox);
function SSI_CustomGraphicalCheckbox() {
    $('input[name="hid_list_[% QuestionName() %]"]').val().split(',').forEach(function(item){
        var id = '[% QuestionName() %]_' + item;
        $('#' + id).closest('.clickable').find('img').toggleClass('selectedImg', SSI_GetValue(id) == 1);
    })
}
</script>



But none of the code snippits from the linked troubleshooting ticket appear to work for the single-select question. Can you help?
asked Jun 20 by Nwiggin Bronze (1,785 points)

1 Answer

0 votes
Please try adding this script to the page, which ought to achieve this behavior for all select questions on the page:

<style>
.select.question .input_cell {
    display: none;
}

.select.question .selected_option img {
    border: 1px solid blue;
}
</style>

<script>
$(document).ready(function(){
    var update = function() {
        $('.select.question').each(function(){
            var qdiv = this;
            var question = qdiv.id.replace(/_div$/, '');
            
            // Radio buttons
            if ($(qdiv).find('input[type="radio"]').length) {
                $(qdiv).find('.selected_option').removeClass('selected_option');
                $('#' + question + '_' + SSI_GetValue(question)).closest('.clickable').find('.option_cell').addClass('selected_option');
            }
            
            // Checkboxes
            else {
                $('input[name="hid_list_' + question + '"]').val().split(',').forEach(function(item){
                    $('#' + question + '_' + item).closest('.clickable').find('.option_cell').toggleClass('selected_option', Boolean(SSI_GetValue(question + '_' + item)));
                });
            }
        });
    };
    SSI_CustomGraphicalRadiobox = update;
    SSI_CustomGraphicalCheckbox = update;
    update();
})
</script>
answered Jun 21 by Zachary Platinum Sawtooth Software, Inc. (206,100 points)
...