Check out the LimeSurvey source code on GitHub!
Welcome, Guest
Username: Password:

TOPIC: How do you put sub code headings into a codeframe?

How do you put sub code headings into a codeframe? 3 years 6 months ago #96098

  • benmok
  • benmok's Avatar
  • Offline
  • Fresh Lemon
  • Posts: 10
  • Karma: 0
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 administrator has disabled public write access.

How do you put sub code headings into a codeframe? 3 years 6 months ago #96143

  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Team
  • Posts: 6575
  • Thank you received: 1477
  • Karma: 579
You can insert those headings with JavaScript. Something like this in the question source:
<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 administrator has disabled public write access.

How do you put sub code headings into a codeframe? 3 years 6 months ago #96152

  • benmok
  • benmok's Avatar
  • Offline
  • Fresh Lemon
  • Posts: 10
  • Karma: 0
Hi thanks for your reply - Where do I put the J script? in the question type CSS?

Thanks,
Ben
The administrator has disabled public write access.

How do you put sub code headings into a codeframe? 3 years 6 months ago #96154

  • benmok
  • benmok's Avatar
  • Offline
  • Fresh Lemon
  • Posts: 10
  • Karma: 0
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 administrator has disabled public write access.

How do you put sub code headings into a codeframe? 3 years 6 months ago #96164

  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Team
  • Posts: 6575
  • Thank you received: 1477
  • Karma: 579
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:
$('.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 administrator has disabled public write access.

How do you put sub code headings into a codeframe? 3 years 6 months ago #96165

  • benmok
  • benmok's Avatar
  • Offline
  • Fresh Lemon
  • Posts: 10
  • Karma: 0
Thank you Tony you totally rock!
The administrator has disabled public write access.

How do you put sub code headings into a codeframe? 3 years 6 months ago #96166

  • benmok
  • benmok's Avatar
  • Offline
  • Fresh Lemon
  • Posts: 10
  • Karma: 0
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 administrator has disabled public write access.

How do you put sub code headings into a codeframe? 3 years 6 months ago #96168

  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Team
  • Posts: 6575
  • Thank you received: 1477
  • Karma: 579
Slightly different for multiple-choice:
<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: 3 years 6 months ago by tpartner.
The administrator has disabled public write access.

How do you put sub code headings into a codeframe? 3 years 6 months ago #96186

  • benmok
  • benmok's Avatar
  • Offline
  • Fresh Lemon
  • Posts: 10
  • Karma: 0
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.
Attachments:
The administrator has disabled public write access.
Time to create page: 0.252 seconds
Imprint                   Privacy policy         General Terms & Conditions         Revocation information and revocation form