Welcome, Guest
Username: Password:

TOPIC: Array filter with exclusive option

Array filter with exclusive option 5 years 8 months ago #48420

Ok great! Thank you.
I'll try this and then check back in a few for the other.
Thanks so much!!!

Dawna
The administrator has disabled public write access.

Array filter with exclusive option 5 years 8 months ago #48421

  • tpartner
  • tpartner's Avatar
  • Online
  • LimeSurvey Team
  • Posts: 5909
  • Thank you received: 1295
  • Karma: 522
And this should show the last two options:
<script type="text/javascript" charset="utf-8">
 
    $(document).ready(function(){
        var itemCount = $('survey-question-answer li').length;
        itemIndex = Number(itemCount-2);
        window.setTimeout(function() {
            $('survey-question-answer li:eq('+itemIndex+')').show();
            $('survey-question-answer li:eq('+itemIndex+') input[type=hidden]:eq(0)').attr('value', 'on');
            $('survey-question-answer li:last').show();
            $('survey-question-answer li:last input[type=hidden]:eq(0)').attr('value', 'on');
        }, 50);
 
    });
 
</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.

Array filter with exclusive option 5 years 8 months ago #48422

Ok we're getting very close here.

The first script you provided worked somewhat...it showed me the Other (please specify) option but not the none of the above option. The second script didn't show either of them so the first one was very close....

Getting there...
Dawna
The administrator has disabled public write access.

Array filter with exclusive option 5 years 8 months ago #48423

  • tpartner
  • tpartner's Avatar
  • Online
  • LimeSurvey Team
  • Posts: 5909
  • Thank you received: 1295
  • Karma: 522
Dawna, I've sent you a PM (and no it's not rude :) )
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.

Array filter with exclusive option 5 years 8 months ago #48424

Thanks Tony.
How do I get it?

Sorry, I am so new to this forum, not sure where to retrieve...
Dawna
The administrator has disabled public write access.

Array filter with exclusive option 5 years 8 months ago #48425

  • tpartner
  • tpartner's Avatar
  • Online
  • LimeSurvey Team
  • Posts: 5909
  • Thank you received: 1295
  • Karma: 522
Go to the homepage and you should see a link in the right column.
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.

Array filter with exclusive option 5 years 8 months ago #48429

  • tpartner
  • tpartner's Avatar
  • Online
  • LimeSurvey Team
  • Posts: 5909
  • Thank you received: 1295
  • Karma: 522
Okay, so if anyone still cares, Dawna and I finally sorted it out. The main hurdles were that she was randomizing the answers of the filtered questions, using the "Other" option for every question and that she wanted the last 2 options to be "sticky".

So the final code is as follows (where the "Other" options are inserted with the LimeSurvey interface and the question code for "None of the above" is 98).

Phew!!!
<script type="text/javascript" charset="utf-8">
 
    $(document).ready(function(){
 
        // Find the survey, group and question IDs
        if($( 'input#fieldnames' ).length != 0) {
            var fieldNames = $('input#fieldnames').attr('value');
            var tmp = fieldNames.split('X');
            var sID = tmp[0];
            var gID = tmp[1];
            var qIDStr = $('div.multiple-opt:eq(0)').attr('id');
            var tmp2 = qIDStr.split('question');
            var qID = tmp2[1];
        }        
 
        // Place the "None of the above" option second last after randomization
        $('li#javatbd'+sID+'X'+gID+'X'+qID+'98').insertBefore($('.survey-question-answer li:last'));
 
        // Set an index for the second last option
        var itemCount = $('.survey-question-answer li').length;
        itemIndex = Number(itemCount-2);
 
        // Show the last two options
        window.setTimeout(function() {
            $('.survey-question-answer li:eq('+itemIndex+')').show();
            $('.survey-question-answer li:eq('+itemIndex+') input[type=hidden]:eq(0)').attr('value', 'on');
            $('.survey-question-answer li:last').show();
            $('.survey-question-answer li:last input[type=hidden]:eq(0)').attr('value', 'on');
        }, 50);
 
    });
 
</script>
Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
Last Edit: 5 years 8 months ago by tpartner.
The administrator has disabled public write access.

Array filter with exclusive option 5 years 2 months ago #58665

  • arielmosto
  • arielmosto's Avatar
  • Offline
  • Junior Lime
  • Posts: 34
  • Karma: 0
Thank you very much. I'm using this script without problems in Firefox and Chrome but crashes in Internet Explorer. I, housed several hours but not how to make it work in IE.

I am using the first script you post:

<script type="text/javascript" charset="utf-8">

$(document).ready(function(){

window.setTimeout(function(){
$('td.answer li:last').show();
$('td.answer li:last input[type=hidden]:eq(0)').attr('value', 'on');
}, 50);

});</script>



Thanks in advance for your help. Ariel
Last Edit: 5 years 2 months ago by arielmosto.
The administrator has disabled public write access.

Array filter with exclusive option 5 years 2 months ago #58667

  • tpartner
  • tpartner's Avatar
  • Online
  • LimeSurvey Team
  • Posts: 5909
  • Thank you received: 1295
  • Karma: 522
Are you getting any JavaScript errors?
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.

Array filter with exclusive option 5 years 2 months ago #58668

  • arielmosto
  • arielmosto's Avatar
  • Offline
  • Junior Lime
  • Posts: 34
  • Karma: 0
Yes, here the print screen:
The administrator has disabled public write access.

Array filter with exclusive option 5 years 2 months ago #58669

  • tpartner
  • tpartner's Avatar
  • Online
  • LimeSurvey Team
  • Posts: 5909
  • Thank you received: 1295
  • Karma: 522
I think you have an error in another script preventing mine from running - I do not use "document.getElementById".

Can you activate a sample survey for us to test?
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.

Array filter with exclusive option 5 years 2 months ago #58670

  • arielmosto
  • arielmosto's Avatar
  • Offline
  • Junior Lime
  • Posts: 34
  • Karma: 0
The administrator has disabled public write access.

Array filter with exclusive option 5 years 2 months ago #58696

  • tpartner
  • tpartner's Avatar
  • Online
  • LimeSurvey Team
  • Posts: 5909
  • Thank you received: 1295
  • Karma: 522
I see no JS errors and the script appears to work in both Firefox and IE.
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.

Array filter with exclusive option 5 years 2 months ago #58716

  • arielmosto
  • arielmosto's Avatar
  • Offline
  • Junior Lime
  • Posts: 34
  • Karma: 0
Thank you very much Tony. I did the sample from Ubuntu and I could not test Internet Explorer to realize that it was working perfect. Then delete the questions that did not work in the original survey, we did back and now everything works correctly in FF, Chrome, IE 6, IE 7 and IE 8. Thank you very much for your help! Ariel
The administrator has disabled public write access.

Array filter with exclusive option 1 year 11 months ago #110285

  • dknvs
  • dknvs's Avatar
  • Offline
  • Fresh Lemon
  • Posts: 12
  • Karma: 0
Hi, Tony
I have a similar issue but the codes that are posted in the forum don't seem to work for my case. I am wondering if you could help me with ediiting the JS codes?

So here is the background for the survey:
We have two multiple select questions. what i select for Q1 will pipe for Q2. People who select "don't know" at Q1 won't see Q2.However, i would like to show "Don't know" for Q2. For the current setting right now, "Don't know" and "Other, please specify" are not showing.

Question 1 (Code Q1) (multiple select question)
1 Answer 1
2 Answer 2
3 Answer 3
DK Don't know (exclusion option)
**Exclusion option:DK


Question2 (Code Q2) (another multiple select question)
1 Answer 1
2 Answer 2
3 Answer 3
Other, please specify
DK Don't know (exclusion option)
**Relevance equation:
((Q1_1.NAOK == "Y" or Q1_2.NAOK == "Y" or Q1_3.NAOK == "Y"))
**Array filter: Q1
**Exclusion option: DK

Thank you so much!

Vicky
The administrator has disabled public write access.
Moderators: ITEd
Time to create page: 0.239 seconds