Welcome to the LimeSurvey Community Forum

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

How do you put sub code headings into a codeframe?

  • benmok
  • benmok's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
10 years 10 months ago #96098 by benmok
This is what I am trying to achieve.....

RESTAURANT:
Cleanliness of restaurant
Design of restaurant
Restaurant ambience

PRODUCT:
Price of food
Portion of food
Presentation of food

I want to be able to display the category headings in a radio list or multiple choice question.

Thanks!
The topic has been locked.
  • tpartner
  • tpartner's Avatar
  • Away
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
10 years 10 months ago #96143 by tpartner
You can insert those headings with JavaScript. Something like this in the question source:
Code:
<script type="text/javascript" charset="utf-8">  
  $(document).ready(function(){
    var qID = {QID};
    var q1 = $('#question'+qID+'');
 
    // Insert some items in the list
    $('.answers-list', q1).prepend('<li>RESTAURANT:</li>');
    $('.answers-list li:eq(3)', q1).after('<li style="padding-top:1em;">PRODUCT:</li>');
  });
</script>

Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
The topic has been locked.
  • benmok
  • benmok's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
10 years 10 months ago #96152 by benmok
Hi thanks for your reply - Where do I put the J script? in the question type CSS?

Thanks,
Ben
The topic has been locked.
  • benmok
  • benmok's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
10 years 10 months ago #96154 by benmok
Hi - I also apologize for not being very technical savvy. Where do I set in the script the position of those sub headings
Many thanks.
Ben
The topic has been locked.
  • tpartner
  • tpartner's Avatar
  • Away
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
10 years 10 months ago #96164 by tpartner

Where do I put the J script?

In the question source - manual.limesurvey.org/Workarounds:_Manip....29_in_LimeSurvey.3F

Where do I set in the script the position of those sub headings

- For the first one, ".prepend" places it a the beginning of the list.
- For the second, the "3" places it after the fourth list item (indexes of list items start a 0). So, for example, if you wanted it after the sixth item, you would use:
Code:
$('.answers-list li:eq(5)', q1).after('<li style="padding-top:1em;">NEW CATEGORY:</li>');

Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
The topic has been locked.
  • benmok
  • benmok's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
10 years 10 months ago #96165 by benmok
Thank you Tony you totally rock!
The topic has been locked.
  • benmok
  • benmok's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
10 years 10 months ago #96166 by benmok
Not sure what i have done wrong here but the subheadings are not showing up.....i have inserted the following into the source. Oh btw i am using a multiple choice with comment question type not sure if that makes any difference in terms of source codes. Thanks Ben
______________________________________________________________________________________________________

You have rated your overall dining experience at our restaurant as<span style="color:#0000ff;"> {INSERTANS:817666X1514X26751}</span>. Please categorise your reason(s) below and provide comments in the corresponding comment box.

<script type="text/javascript" charset="utf-8">
$(document).ready(function(){
var qID = {QID};
var NPSreason = $('#question'+qID+'');

// Insert some items in the list
$('.answers-list', NPSreason).prepend('<li>CUSTOMER SERVICE PERSON:</li>');
$('.answers-list li:eq(4)', NPSreason).after('<li style="padding-top:1em;">RESTAURANT:</li>');
$('.answers-list li:eq(9)', NPSreason).after('<li style="padding-top:1em;">PRODUCT:</li>');
});
</script>
The topic has been locked.
  • tpartner
  • tpartner's Avatar
  • Away
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
10 years 10 months ago - 10 years 10 months ago #96168 by tpartner
Slightly different for multiple-choice:
Code:
<script type="text/javascript" charset="utf-8">  
  $(document).ready(function(){
    var qID = {QID};
    var NPSreason = $('#question'+qID+'');
 
    // Insert some items in the list
    $('.subquestions-list', NPSreason).prepend('<li>CUSTOMER SERVICE PERSON:</li>');
    $('.subquestions-list li:eq(4)', NPSreason).after('<li style="padding-top:1em;">RESTAURANT:</li>');
    $('.subquestions-list li:eq(9)', NPSreason).after('<li style="padding-top:1em;">PRODUCT:</li>');
  });
</script>

Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
Last edit: 10 years 10 months ago by tpartner.
The topic has been locked.
  • benmok
  • benmok's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
10 years 10 months ago #96186 by benmok
Thanks Tony that work beautifully!

While I have you here if you don't mind me asking 2 more questions.

1) Is there a way to only activate those comment fields for the selected multiple response codes?

2) Is there a way to make the comment field mandatory?

Please see attached image.
The topic has been locked.

Lime-years ahead

Online-surveys for every purse and purpose