Have an idea?

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

Subheaders and Loops

Hello,

I have two select questions on the same page with sub headers.

The first select question is a single punch and I am using this code

<script>
$(document).ready(function(){
    // Parameters
    var subheaders = [
        [1, 9, '<b>External or Combination Parasite Control (Please select one only)</b>']
         
    ];

    // Question type
    var closest = '.response_row';
    if ($('#[% QuestionName() %]_div.constantsum').length) {
        closest = 'tr';
    }

    // Subheaders
    var list = $('input[name=hid_list_[% QuestionName() %]]').val().split(',').map(Number);
    subheaders.forEach(function(subheader){
        var earliestIndex = 9999;
        for (var item = subheader[0]; item <= subheader[1]; item++) {
            var thisIndex = list.indexOf(item);
            if (thisIndex != -1 && thisIndex < earliestIndex) {
                earliestIndex = thisIndex;
            }
        }
        if (earliestIndex != 9999) {
            $('#[% QuestionName() %]_' + list[earliestIndex]).closest(closest).before(subheader[2]);
        }
    });
})
</script>


The second select question is a multiple punch question and I am using this code

<script>
$(document).ready(function(){
    // Parameters
    var subheaders = [
        [10, 17, '<b>Dewormers/Internal Parasite Control (Please select all that apply)</b>']
         
    ];

    // Question type
    var closest = '.response_row';
    if ($('#[% QuestionName() %]_div.constantsum').length) {
        closest = 'tr';
    }

    // Subheaders
    var list = $('input[name=hid_list_[% QuestionName() %]]').val().split(',').map(Number);
    subheaders.forEach(function(subheader){
        var earliestIndex = 9999;
        for (var item = subheader[0]; item <= subheader[1]; item++) {
            var thisIndex = list.indexOf(item);
            if (thisIndex != -1 && thisIndex < earliestIndex) {
                earliestIndex = thisIndex;
            }
        }
        if (earliestIndex != 9999) {
            $('#[% QuestionName() %]_' + list[earliestIndex]).closest(closest).before(subheader[2]);
        }
    });
})
</script>


In addition I am looping these 2 questions along with a 3rd question on a different page.

The first iteration the sub-headers look GREAT.

The second iteration the sub-headers text is appearing twice (duplicate).

How can I fix this?

Thank you in advance
asked Jan 21 by Sandy
I'm not seeing the doubling behavior.  Is there any other code on the page that might be relevant?

Alternatively, there may be an issue specific to your version of SSI Web / Lighthouse Studio.  What version are you running?
No, there is no code other than what I specified.

I am running the survey on 9.6.1.
I upgraded to 9.8.1 and it works fine.  Thank you

Your solution to the original question

Please only use this to answer the original question. Otherwise please use comments.
Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.
Anti-spam verification:

To avoid this verification in future, please log in or register.
...