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

TOPIC: Expressions in dropdown fields + hide empty dropdown fields

Expressions in dropdown fields + hide empty dropdown fields 4 years 3 days ago #89810

  • snieuw
  • snieuw's Avatar
  • Offline
  • Fresh Lemon
  • Posts: 5
  • Karma: 0
Hi everybody,
I would like to have an if(....) statement in one of the optional answer of a dropdown question. this should either show a certain string, or leave this field empty. afterwards, i wanted to hide empty anwers.
I have done this with array questions (works perfectly!), but somehow this expression is not executed here.

Maybe because it is in the same questiongroup? Anything I can do, to make this work in one questiongroup? And even if this DOES work: how do i hide empty elements?

Example survey is attached. it should show "a","b","c","d" if "yes" is selected, otherwise "a","b","d"

Sorry for the two combined questions, but i figured they were connected...

Thanks a lot for every hint or suggestion!!

The administrator has disabled public write access.

Expressions in dropdown fields + hide empty dropdown fields 4 years 2 days ago #89829

  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Team
  • Posts: 6574
  • Thank you received: 1477
  • Karma: 579
I can't speak to why EM is not piping the text, you may want to file a bug report.

Regarding the hiding/showing of the drop-down option, this gets a little tricky. You can't hide the option across all browsers with "display;none" so you need to create a clone of it and then completely remove or add it to the select (drop-down) element as required.

Below is some code to do this with your example survey.
<script type="text/javascript" charset="utf-8">
		var dynamicOption = 'A2'; // Answer code of the dynamic dropdown option
		var toggleRadio = 'A1'; // Answer code of the "Yes" radio answer
		// Create a clone of the dynamic option
		var optClone = $('option[value="'+dynamicOption+'"]').clone();
		// Define the element directly preceding the dynamic option
		var optPre = $('option[value="'+dynamicOption+'"]').prev('option');
		// Initially remove the dynamic option
		$('select option[value="'+dynamicOption+'"]').remove();
		// Listener on the radios
			// If "Yes" selected, insert the dynamic option
			if($(this).attr('value') == toggleRadio) {
				if($('select option[value="'+dynamicOption+'"]').length == 0) {
			// Otherwise remove the dynamic option
			else {
				$('select option[value="'+dynamicOption+'"]').remove();
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.
Time to create page: 0.218 seconds
Imprint                   Privacy policy         General Terms & Conditions         Revocation information and revocation form