Welcome to the LimeSurvey Community Forum

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

Fill dropdown list options with previous dropdown list answers

  • FaLifeTime
  • FaLifeTime's Avatar Topic Author
  • Offline
  • Junior Member
  • Junior Member
More
3 years 8 months ago #204357 by FaLifeTime
Hello everybody:
I’ve been hanging around with some limesurvey headaques for a while. Maybe someone can give me a hand.

I have three sort of related situations.

1)In one group I have several dropdown lists (eight) where the user has to choose among a lot of options. In the following group/view, the first question it’s another dropdown list item and i want to dinamically fill it with the values from the previuos dropdown list answers. I’ve trying things like this . But It’s always and end point.

2)I have a two columns Array(Texts) item where each option/cel it’s a dropdown list in order to normalize the inputs. There is only one option from the first column that if the user select it, the corresponding value from the second column should be an specific value.

For example: Array(text)

Column 1 (dropdown list)
Op1: Yes
Op2: No

Column 2 (dropdown list)
Op1: Shared
Op2: Personal
Op3: Not applicable


The third option (Op3) should only automatically appears if Op2 in column 1 is chosen.

3) Its the same situation as 1) with the only difference that I have to prefill a dropdown list options with the previuos dorpdown list answer in the same group/view.


Thanks in advance for any help.
4aLifeTime
The topic has been locked.
  • Joffm
  • Joffm's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
3 years 8 months ago #204369 by Joffm
Which version are you using?

The mentioned script is for version 1.92, so it is rather probable that it doesn't work in an actual version.

You should attach a sample of these questions as lss export.

Joffm

Volunteers are not paid.
Not because they are worthless, but because they are priceless
The topic has been locked.
  • FaLifeTime
  • FaLifeTime's Avatar Topic Author
  • Offline
  • Junior Member
  • Junior Member
More
3 years 8 months ago #204370 by FaLifeTime
Hi Joffm. Thanks for your quick reply. You re right i've just forgotten to mention my Limesurvey installation version. Its 3.17.

I couldn't achieved anything with sense with JS code. Let me know what kind of structure would help to share in a lss file. Even whether there is some documentation i can read about it.

Thanks,
FaLifeTime
The topic has been locked.
  • FaLifeTime
  • FaLifeTime's Avatar Topic Author
  • Offline
  • Junior Member
  • Junior Member
More
3 years 8 months ago - 3 years 8 months ago #204393 by FaLifeTime
About point 1) I'm trying to do something like this. I changed the dropdown list for a radio list. After that i filled every answer of the radio list like this.

A1 = {p072.shown}
A2 = {p073.shown}
.
.
.
A8 = {p078.shown}

And now i'm trying to follow this code from this link (thats why i changed into radio list) but when the group/section changes the radio list always is empty
Code:
 
<script type="text/javascript" charset="utf-8">
  $(document).ready(function(){
 
    $('.list-radio li.radio-item').each(function(i){
      if($('.answertext', this).text() == '') {
        $(this).hide();
      }
    });
 
  });
 
</script>
 


Is there anything that i'm doing wrong?

Thanks,
4aLifeTime
Last edit: 3 years 8 months ago by FaLifeTime.
The topic has been locked.
  • Joffm
  • Joffm's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
3 years 8 months ago #204396 by Joffm
This script is more than seven years old and for a different LimeSurvey version 1.92 or 2.05.

Since version 2.50/2.73 and 3.x. LimeSurvey uses the bootstrap library, so most of these old scripts don't work.

Joffm

And again: send your survey as lss export

Volunteers are not paid.
Not because they are worthless, but because they are priceless
The topic has been locked.
  • FaLifeTime
  • FaLifeTime's Avatar Topic Author
  • Offline
  • Junior Member
  • Junior Member
More
3 years 8 months ago #204398 by FaLifeTime
Hi Joffm. You’re right. That code belongs to a very old limesurvey version. Searching through the forums and the official documentation I didn’t find another way to solve it.

As you said, It make it more clear if I exemplify with a concrete demo survey.
I tried to recreate my general situation.

In the initial group/section of questions I have a first dropdown list item (p001) with some careers (Spanish). Next an input with the number of seminars taken during the first semester (p002) and depending on that value and the specific career some news dropdown list items shows up with filtered options.

I also solve this using a very old workaround. There I have a CSS problem that the width property of the filtered dropdown list items is 0% so I can’t properly display the inputs. The js code is at the end of the post.

After all the first section, the next group of questions belongs to a Radio List item (p006) where I pretend to only show the options selected in the dropdown list items (p003,p004,p005). I would have prefered to solve it with another dropdown list but i thought that the radio list item solution that a i found would make my task easier.

So, to make it clear. In the first group of questions, I’m using an old js workaround to do the filtering. I have a CSS problem there at the time the dropdown list seminars shows up.

At the second group of questions, I tried to show up only the options selected in the dropdown list items (p003,p004,p005). I used an old workaround for that and it doesn’t work.

js code for filtering
Code:
 
function selectFilterByCode(qID,filterqID){
  $(document).ready(function(){
    var idSelectFilter = $("#question"+qID).find("select").attr('id');
    $("#"+idSelectFilter).hide();
    var idSelectFiltering = $("#question"+filterqID).find("select").attr('id');
    if(typeof idSelectFilter === 'undefined' || typeof idSelectFiltering === 'undefined' )
    { 
      return false;
    }
    else
    {
      var idNewSelectFilter = 'select'+qID
      var NewSelectElement = "<select id='"+idNewSelectFilter+"'><option value=''>"+$("#"+idSelectFilter+" option[value='']:first").text()+"</option></select>";
      $("#"+idSelectFilter).after(NewSelectElement);
      //$("#"+idNewSelectFilter).width="0%";
      $("#"+idSelectFiltering).change(function(){
        $('#'+idSelectFilter).val('');
        $('#'+idNewSelectFilter).val('');
        var valuefilter=$(this).val();
        $('#'+idNewSelectFilter+' option').not(':first').remove();
        $('#'+idSelectFilter+' option').each(function(){
          if($(this).attr('value').indexOf(valuefilter)==0){
            $(this).clone().appendTo('#'+idNewSelectFilter);
          }
        });
      });
 
      $("#"+idNewSelectFilter).change(function(){
        $('#'+idSelectFilter).val($(this).val());
      });
 
      if($("#"+idSelectFiltering).val()!=''){
        var valuefilter=$("#"+idSelectFiltering).val();
        $('#'+idSelectFilter+' option').each(function(){
          if($(this).attr('value').indexOf(valuefilter)==0){
            $(this).clone().appendTo('#'+idNewSelectFilter);
          }
        });
        if($("#"+idSelectFilter).val()!=''){
           $('#'+idNewSelectFilter).val($("#"+idSelectFilter).val());
        }
      }
    }
  });
}
 


I hope I made myself clear. Just let me know.

Thanks!
4aLifeTime
Attachments:
The topic has been locked.
  • Joffm
  • Joffm's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
3 years 8 months ago #204405 by Joffm
Regarding p006:
You can do this without javascript.
The usual procedure by inserting a hidden question of type multiple, setting the necessary options by an equation and using this as array filter of p006.

File Attachment:

File Name: limesurvey...7697.lss
File Size:43 KB


Joffm

Volunteers are not paid.
Not because they are worthless, but because they are priceless
The following user(s) said Thank You: FaLifeTime
The topic has been locked.
  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
3 years 8 months ago #204407 by tpartner
We cannot help with the first problem because there is a dependency - selectfilter.js - which you have not provided.

Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
The topic has been locked.
  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
3 years 8 months ago - 3 years 8 months ago #204408 by tpartner
...it occurs to me that the first filtering problem could be solved with several new questions instead of filtering.

Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
Last edit: 3 years 8 months ago by tpartner.
The topic has been locked.
  • FaLifeTime
  • FaLifeTime's Avatar Topic Author
  • Offline
  • Junior Member
  • Junior Member
More
3 years 8 months ago #204411 by FaLifeTime
Thanks both for the replies.

Joffm, It works as you did it. I gonna try to recreate it. The thing is that what i sent was a short example. I have 1200 options in each dropdown list at the first section. And there are 8 dropdown list. So I'm trying to do something like this by 1200

{m104_A1=if(p003=="A1" or p004=="A1" or p005=="A1" or p006=="A1" or p007=="A1" or p008=="A1" or p009=="A1" or p010=="A1","Y","")}

tpartner, thanks. I'm not sure what you mean with "there is a dependency - selectfilter.js - which you have not provided". Is the code that I pasted in my code. I took it from here from DenisChenus. A very old post.

Thanks,
4aLifeTime
The topic has been locked.
  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
3 years 8 months ago - 3 years 8 months ago #204413 by tpartner
In your question source, there are script tags:
Code:
<script type='text/javascript' src='{TEMPLATEURL}/files/selectfilter.js'>

It would be easier to debug if you provide all required scripts instead of portions of them.

You have a fatal JavaScript error in the script in p002. It is looking for an array question which does not exist. Remove that script.

In the selectfilter.js file, change:

Code:
var NewSelectElement = "<select id='"+idNewSelectFilter+"'><option value=''>"+$("#"+idSelectFilter+" option[value='']:first").text()+"</option></select>";

To:

Code:
var NewSelectElement = "<select id='"+idNewSelectFilter+"' class='form-control list-question-select'><option value=''>"+$("#"+idSelectFilter+" option[value='']:first").text()+"</option></select>";

It then works as expected for me.


Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
Last edit: 3 years 8 months ago by tpartner.
The topic has been locked.
  • FaLifeTime
  • FaLifeTime's Avatar Topic Author
  • Offline
  • Junior Member
  • Junior Member
More
3 years 8 months ago - 3 years 8 months ago #204416 by FaLifeTime
tpartner, thanks. You were right, I had that unnecesary code there in p002. I also changed the code in the selectfilter js file as you mentioned but i still having the css problem. If I press Ctrl F5 then it works perfectly. I don't understand why that happens.

There is a picture what happens. If I refresh the survey then it works.



If I click the options shows up, as if the element is hidden.
Last edit: 3 years 8 months ago by FaLifeTime.
The topic has been locked.

Lime-years ahead

Online-surveys for every purse and purpose