Welcome to the LimeSurvey Community Forum

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

array filter in sub answer

  • nibos
  • nibos's Avatar Topic Author
  • Offline
  • Senior Member
  • Senior Member
More
8 years 5 months ago #127570 by nibos
array filter in sub answer was created by nibos
Can I hide an array answers as in the attached image?
Attachments:
The topic has been locked.
  • holch
  • holch's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
8 years 5 months ago #127574 by holch
Replied by holch on topic array filter in sub answer
This is not a question about the development of the limesurvey software, but rather of what you can do with Limesurvey. I'll move it to the correct forum.

I answer at the LimeSurvey forum in my spare time, I'm not a LimeSurvey GmbH employee.
No support via private message.

The topic has been locked.
  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
8 years 5 months ago - 8 years 4 months ago #127592 by tpartner
Replied by tpartner on topic array filter in sub answer
Set up your survey to use JavaScript and add something like this to the question source:

Code:
<script type="text/javascript" charset="utf-8">    
  $(document).ready(function(){
    //Hide the last radio in the first row
    $('#question'+{QID}+' tr.answers-list:first input.radio:last').remove();
  });
</script>

Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
Last edit: 8 years 4 months ago by tpartner.
The topic has been locked.
  • nibos
  • nibos's Avatar Topic Author
  • Offline
  • Senior Member
  • Senior Member
More
8 years 5 months ago #127596 by nibos
Replied by nibos on topic array filter in sub answer
Tpartner,

Thank you very much for that. It worked.

I want to do almost the same with Multiple choice with comments (see attached). Is it feasible? Your help is very important.



Thank you in advance.
Attachments:
The topic has been locked.
  • holch
  • holch's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
8 years 5 months ago #127607 by holch
Replied by holch on topic array filter in sub answer
Hi Tpartner, this works great. However, is there a way to subsitute "first" and "last" with a specific answer option? Just to add more flexibility. Because if the array is randomized, "first" and "last" might not work, or if I would actually hide the middle button for a specific question. Is there a way to make this script more flexible?

I answer at the LimeSurvey forum in my spare time, I'm not a LimeSurvey GmbH employee.
No support via private message.

The topic has been locked.
  • holch
  • holch's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
8 years 5 months ago - 8 years 5 months ago #127640 by holch
Replied by holch on topic array filter in sub answer
hehehehe, sometimes it is good when Tpartner isn't responding quickly. I had a little break and used it to learn a little bit. Searched for "javascript :last" and found a page about potential selectors here: www.w3schools.com/jquery/jquery_ref_selectors.asp

So I played around a little and found :eq(x) as a selector. This wouldn't work if the question is randomized, so I am still looking for this, but at least this is more flexible than first and last as selectors.

So in addition to the last radio button of the first line, I also hid the 3rd button of the 3rd line:
Code:
<script type="text/javascript" charset="utf-8">    
  $(document).ready(function(){
    //Hide the last radio in the first row
    $('#question'+{QID}+' tr.answers-list:first input.radio:last').hide();
                $('#question'+{QID}+' tr.answers-list:eq(2) input.radio:eq(2)').hide();
  });
</script>

And here how it looks like:


I answer at the LimeSurvey forum in my spare time, I'm not a LimeSurvey GmbH employee.
No support via private message.

Last edit: 8 years 5 months ago by holch.
The topic has been locked.
  • holch
  • holch's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
8 years 5 months ago #127642 by holch
Replied by holch on topic array filter in sub answer
OK, so with a little playing around I finally found a good solution that is also "randomization" save, or at least should be from my understanding.
Code:
<script type="text/javascript" charset="utf-8">    
  $(document).ready(function(){
    //Hide the last radio in the first row
    $('#question'+{QID}+' tr.answers-list:first input.radio:last').hide();
                //Hide the 3rd radio in the 3rd row
                $('#question'+{QID}+' tr.answers-list:eq(2) input.radio:eq(2)').hide();
                //Hide the first radio of Option 4
                $('#answer433587X129X10164-1').hide();
  });
</script>



This should work with the comment boxes as well. Will give it a try later. But there is one flaw to this method. While the radio buttons don't show, it seems that they can still be clicked. Is there any way to avoid this?

I answer at the LimeSurvey forum in my spare time, I'm not a LimeSurvey GmbH employee.
No support via private message.

The following user(s) said Thank You: delarammahdaviii
The topic has been locked.
  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
8 years 5 months ago #127650 by tpartner
Replied by tpartner on topic array filter in sub answer

While the radio buttons don't show, it seems that they can still be clicked.

Ah, good point - replace all instances of :
Code:
.hide()
with:
Code:
.remove()

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: holch
The topic has been locked.
  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
8 years 5 months ago #127652 by tpartner
Replied by tpartner on topic array filter in sub answer
This will remove the comment field from the first row of a multiple-choice-with-comments question. As Holch suggests, if you want to randomize, you will need to use a more specific selector.

Code:
<script type="text/javascript" charset="utf-8">    
  $(document).ready(function(){
    $('#question{QID} li.question-item:eq(0) span.comment').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: delarammahdaviii
The topic has been locked.
  • delarammahdaviii
  • delarammahdaviii's Avatar
  • Offline
  • Senior Member
  • Senior Member
More
8 years 1 month ago - 8 years 1 month ago #131047 by delarammahdaviii
Replied by delarammahdaviii on topic array filter in sub answer
hi
what's code for array ( number ) ?

boriginal wrote:

Code:
<script type="text/javascript" charset="utf-8">    
  $(document).ready(function(){
 
                //Hide what ever you want by adding the code of your interactive element
                $('#cbox_585145X141X34956_1').hide();
  });
</script>

Last edit: 8 years 1 month ago by delarammahdaviii.
The topic has been locked.
  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
8 years 1 month ago #131049 by tpartner
Replied by tpartner on topic array filter in sub answer
Please explain exactly what you are trying to do.

Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
The topic has been locked.
  • delarammahdaviii
  • delarammahdaviii's Avatar
  • Offline
  • Senior Member
  • Senior Member
More
8 years 1 month ago #131051 by delarammahdaviii
Replied by delarammahdaviii on topic array filter in sub answer
thanks for help
i want do this
The topic has been locked.

Lime-years ahead

Online-surveys for every purse and purpose