Have an idea?

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

How do I add a counter to a multiple select question?

Hi, I've created a multiple response question in SSIWeb 8 with 30 items and asking them to select 15 items.  I'd like the respondents to see how many they've selected, so a running count of the number of clicks/checks.  Would someone know how to do this , i.e. what code would I need to put and where would I put it?

Thanks!!
Pina.
asked Apr 4, 2019 by Pina
edited Apr 4, 2019

1 Answer

+2 votes
Place this where you want the total to appear:

<span class="checkboxCount"></span>


Then place this in the question's footer:

<script>
$(document).ready(function(){
    updateCheckboxCount();
})

function SSI_CustomGraphicalCheckbox() {
    updateCheckboxCount();
}

function updateCheckboxCount() {
    var count = 0;
    $('input[name="hid_list_[% QuestionName() %]"]').val().split(',').forEach(function(item){
        if (SSI_GetValue('[% QuestionName() %]_' + item)) {
            count++;
        }
    });
    $('.checkboxCount').text(count);
}
</script>
answered Apr 4, 2019 by Zachary Platinum Sawtooth Software, Inc. (216,575 points)
Hi there, I just tried this but I'm getting a 0 as the count, it doesn't change as I check the boxes.  Is there anything in your script that I need to change  to make it work with my study?  Because I literally just copy/pasted in the places you mention.
Have you disabled graphical radio buttons and checkboxes in your survey settings, by chance?
Yes, I have, I am using non-graphical radio button/checkboxes.  Is that an issue?
To work with non-graphical checkboxes, replace lines 6-8 of my script with this:

$(document).on('click', '#[% QuestionName() %]_div .clickable', function(){
    updateCheckboxCount();
})
perfect!!! Thank you so much :-)
...