Check out the LimeSurvey source code on GitHub!

Change Question Group description based on token

More
5 years 8 months ago #61735 by waitz
Is there a way I can hack my way into changing a question group description based on a value in one of my tokens?

Version 1.91+ Build 11232 | PHP 5.3.9 | MySQL 5.1.56 |

Please Log in to join the conversation.

More
5 years 8 months ago #61779 by tpartner
You can use JavaScript to dynamically change the description. The details would vary by template but this should work for the default template.

1) Set up your survey to use JavaScript .

2) Add the following script to the source of the group description.
<script type="text/javascript" charset="utf-8">
 
	$(document).ready(function() {
 
		if('{TOKEN:ATTRIBUTE_1}' == 'x') {
			$('span.group-description').text('Some new group description.');
		}
 
	});
 
</script>

Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.

Please Log in to join the conversation.

More
5 years 8 months ago #61785 by waitz
Great, interesting. I have already set it up for javascript, so I'll try adding the code.

Could I use the same idea for showing / hiding some of the sub questions in a 'Multiple options with comments': www.limesurvey.org/en/forum/can-i-do-thi...ition-on-subquestion ?

Version 1.91+ Build 11232 | PHP 5.3.9 | MySQL 5.1.56 |

Please Log in to join the conversation.

More
5 years 8 months ago #61787 by tpartner
I just posted a solution there.

Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.

Please Log in to join the conversation.

More
5 years 8 months ago - 5 years 8 months ago #62171 by waitz
Hmmm, I actually don't get this one to work.

I changed the information above to:

'{TOKEN:ATTRIBUTE_30}' == '1'

So that if token 30 has value 1, show the following text. But it will not show....
Any reason?

Version 1.91+ Build 11232 | PHP 5.3.9 | MySQL 5.1.56 |
Last Edit: 5 years 8 months ago by waitz.

Please Log in to join the conversation.

More
5 years 8 months ago #62173 by tpartner
Are you using the default template?

Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.

Please Log in to join the conversation.

More
5 years 8 months ago #62174 by waitz
I used limespired, otherwise everything else is default.

Version 1.91+ Build 11232 | PHP 5.3.9 | MySQL 5.1.56 |

Please Log in to join the conversation.

More
5 years 8 months ago #62175 by tpartner
Try this:
<script type="text/javascript" charset="utf-8">
 
	$(document).ready(function() {
 
		if('{TOKEN:ATTRIBUTE_30}' == '1') {
			$('.survey-groupdescription').text('Some new group description.');
		}
 
	});
 
</script>

Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.

Please Log in to join the conversation.

More
5 years 8 months ago #62178 by waitz
Yepp, that was it. Thanks again!

Version 1.91+ Build 11232 | PHP 5.3.9 | MySQL 5.1.56 |

Please Log in to join the conversation.

Imprint                   Privacy policy         General Terms & Conditions         Revocation information and revocation form