Welcome to the LimeSurvey Community Forum

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

Hide answer option with EM, is it possible?

  • marzopiter
  • marzopiter's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
9 years 7 months ago #111569 by marzopiter
Hi Folks,
I have 10 token attributes (hospitals that doctors attends)
This is passed as attributes in a list question. One Doctor could attend in many hospital, but one each time. My doubt is: is there any way to remove from the list that one withou information (some doctors could attend from 1 to 10 hospitals, but some could have 3 opiton, another could have 6 ans so on.
In attibute list, I can do something like:
{if(!is_empty({TOKEN:ATTRIBUTE_1}),Q23_1.show,Q23_1.hide)}
{if(!is_empty({TOKEN:ATTRIBUTE_2}),Q23_2.show,Q23_2.hide)}
...
Is this possible? I try with javascript, but I´m missing something, cause just hide the checkbox with this script:

<script>
$(document).ready(function(){
if($('#100052X79X203621').is(':empty')){
$('#100052X79X203621').hide();
}
});
</script>

Could somebody put a light on this, please?
The topic has been locked.
  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
9 years 7 months ago #111583 by tpartner
Replied by tpartner on topic Hide answer option with EM, is it possible?
You can add something like this to the source of the multiple-choice question:

Code:
<script type="text/javascript" charset="utf-8">  
    $(document).ready(function() { 
 
    // Identify this question
    var thisQuestion = $('#question'+{QID}+'');
 
    // The attribute values
    var attribute1 = '{TOKEN:ATTRIBUTE_1}';
    var attribute2 = '{TOKEN:ATTRIBUTE_2}';
    var attribute3 = '{TOKEN:ATTRIBUTE_3}';
    var attribute4 = '{TOKEN:ATTRIBUTE_4}';
    var attribute5 = '{TOKEN:ATTRIBUTE_5}';
 
    if(attribute1 == '') {
      $('li.question-item:eq(0)', thisQuestion).hide();
    }
    if(attribute2 == '') {
      $('li.question-item:eq(1)', thisQuestion).hide();
    }
    if(attribute3 == '') {
      $('li.question-item:eq(2)', thisQuestion).hide();
    }
    if(attribute4 == '') {
      $('li.question-item:eq(3)', thisQuestion).hide();
    }
    if(attribute5 == '') {
      $('li.question-item:eq(4)', thisQuestion).hide();
    }
  });
</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.
More
9 years 4 months ago #113991 by Loktar
Replied by Loktar on topic Hide answer option with EM, is it possible?
Nice!

I also wonder if there is a way to hide Answers/Subquestions depending on previous answers.

This could be great to Have answer and subquestion list that adapts to previous answers, because right now i need to create multiple question each time, creating more column in my DB.

Example: on Q3 i have a question that as 3 answers if you are a customer OR 7 i you are an employee. Right now i have no other choice but to create separate questions with all the subquestions, it's a bit messy :/
The topic has been locked.
  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
9 years 4 months ago #113997 by tpartner
Replied by tpartner on topic Hide answer option with EM, is it possible?
If the "respondent type" question is on a previous page and, for example, has a question code of "Q1" and answer codes 1 (customer) and 2 (employee), you can try something like this:

Code:
<script type="text/javascript" charset="utf-8">  
    $(document).ready(function() { 
 
    // Identify this question
    var thisQuestion = $('#question'+{QID}+'');
 
    if({Q1.NAOK} == '1') {
      $('li.question-item:eq(3)', thisQuestion).hide();
      $('li.question-item:eq(4)', thisQuestion).hide();
      $('li.question-item:eq(5)', thisQuestion).hide();
      $('li.question-item:eq(6)', thisQuestion).hide();
    }
  });
</script>

Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
The following user(s) said Thank You: Loktar
The topic has been locked.
More
9 years 4 months ago #114005 by Loktar
Replied by Loktar on topic Hide answer option with EM, is it possible?
Man, this works perfectly ! Thanks a lot!

Also this kind of features is on the top list of the most demanded feature on LS,
so i guess that a lot of people would benefit your work by knowing this while waiting
for further LS version.


And oh, thanks, again B)
The topic has been locked.

Lime-years ahead

Online-surveys for every purse and purpose