Welcome to the LimeSurvey Community Forum

Ask the community, share ideas, and connect with other LimeSurvey users!

Insert Labels in Array Rows for Conjoint

  • DVP17lemon
  • DVP17lemon's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
5 years 5 months ago - 5 years 5 months ago #175986 by DVP17lemon
Insert Labels in Array Rows for Conjoint was created by DVP17lemon
Hello, I want to insert text labels like 'Yes' and 'No' into rows of an array. Those labels depend on another random variable that is created in the survey called "RANDOM".

The result should look like this attached image:


I have tried to find a solution from this thread: www.limesurvey.org/forum/design-issues/1...ubheaders-and-labels
Unfortunately, I have almost no experience using JavaScript.


My main problem is to implement a placeholder into JavaScript that refers to my RANDOM variable.

The code that I tried -- that does NOT work -- looks like this:
Code:
<script type="text/javascript" charset="utf-8">  
    $(document).ready(function(){
 
    // Identify this question
    var thisQuestion = $('#question{QID}');
 
        var placeHoldOne = $('#question{if(RANDOM == 1 or RANDOM == 2, "Yes", "No")}');
        var placeHoldTwo = $('#question{if(RANDOM == 1 or RANDOM == 2, "Yes", "No")}');
        var placeHoldThr = $('#question{if(RANDOM == 1 or RANDOM == 3, "Yes", "No")}');
        var placeHoldFou = $('#question{if(RANDOM == 1 or RANDOM == 4, "Yes", "No")}');
 
    // Insert the new header row
    $('tr.answers-list:eq(0)', thisQuestion).before('<tr class="ls-heading"><td class="" style="text-align: left;">Option 1</td>'+'<th class="answer-text">'+placeHoldOne+'</th>'+'<th class="answer-text">'+placeHoldTwo+'</th></tr>');
        $('tr.answers-list:eq(0)', thisQuestion).before('<tr class="ls-heading"><td class="" style="text-align: left;">Option 2</td>'+'<th class="answer-text">'+placeHoldThr+'</th>'+'<th class="answer-text">'+placeHoldFou+'</th></tr>');
  });
</script>

Attached is the whole conjoint survey with the random variable.
Thank you very much for your attention!
Last edit: 5 years 5 months ago by DVP17lemon.
The topic has been locked.

Lime-years ahead

Online-surveys for every purse and purpose