Willkommen, Gast
Benutzername: Passwort: Angemeldet bleiben:

THEMA: Dropdownlist as a subquestion depending on first dropdown question

Re: Dropdownlist as a subquestion depending on first dropdown question 1 Jahr 9 Monate her #88943

  • Mazi
  • Mazis Avatar
  • OFFLINE
  • LimeSurvey Team
  • Beiträge: 5324
  • Dank erhalten: 294
  • Karma: 248
lfortunato schrieb:
At last, it works! :) :) :)

I want to thank very much Denis for his helpfulness and kindness.
Now It works also with the category separator, and this is exactly what I needed to do!
Good job to all the Limesurvey team!!!
You're welcome :-)

If our hints have been helpful and you enjoy limesurvey please consider a donation to give Limesurvey a future .
We do all this in our free time and you don't have to pay a penny for this software.

Without your help we can't keep this project alive.

Best regards/Beste Grüße,
Dr. Marcel Minke
(Limesurvey Head of Support)
Need Help? We offer professional Limesurvey support
Contact: marcel.minke(at)limesurvey.org'"
Der Administrator hat öffentliche Schreibrechte deaktiviert.

Re: Dropdownlist as a subquestion depending on first dropdown question 1 Jahr 9 Monate her #88961

  • lfortunato
  • lfortunatos Avatar
  • OFFLINE
  • Junior Lime
  • Beiträge: 38
  • Dank erhalten: 1
  • Karma: 1
You are right, Mazi...
I have already said to my boss that a donation would be important for LS team and certainly for us, as users...

Many thanks to all you :)
Der Administrator hat öffentliche Schreibrechte deaktiviert.

Re: Dropdownlist as a subquestion depending on first dropdown question 1 Jahr 6 Monate her #92203

  • Gormack
  • Gormacks Avatar
  • OFFLINE
  • Fresh Lemon
  • Beiträge: 1
  • Karma: 0
Thank you for your nice solution above.
For those who wants to link more than 2 dropdown lists (list3 link to list2 link to list1) see below the small changes to apply into the code


$("#"+idSelectFilter).after(NewSelectElement);

to b replaced by

$("#"+idSelectFilter).before(NewSelectElement);

Thanks
Der Administrator hat öffentliche Schreibrechte deaktiviert.

Re: Dropdownlist as a subquestion depending on first dropdown question 1 Jahr 2 Monate her #97375

  • Gabriela
  • Gabrielas Avatar
  • OFFLINE
  • Senior Lime
  • Beiträge: 64
  • Karma: 0
HI,
Im trying to achieve this but I cant make it work.
3 droplists,

1. Droplist 1
2. Droplist 2
3. Droplist 3

Droplist 2 depends on droplist 1
Droplist 3 depends on droplist 2

How can I adapt the code and / or implementation to achieve this?
thanks a lot.
Gabi
Der Administrator hat öffentliche Schreibrechte deaktiviert.

Re: Dropdownlist as a subquestion depending on first dropdown question 1 Jahr 2 Monate her #97383

  • Gabriela
  • Gabrielas Avatar
  • OFFLINE
  • Senior Lime
  • Beiträge: 64
  • Karma: 0
And last question..

Im trying to retrieve the answer from the droplists, using INSERTANS , but its not possible as the select created with the java script has a different type of code (select3111)
is it possible to retrive the answer by other means?

thanks!!
Der Administrator hat öffentliche Schreibrechte deaktiviert.

Re: Dropdownlist as a subquestion depending on first dropdown question 1 Jahr 1 Monat her #98037

  • Gabriela
  • Gabrielas Avatar
  • OFFLINE
  • Senior Lime
  • Beiträge: 64
  • Karma: 0
Sorry to insist..I really need this :unsure:

1. Droplist 1
2. Droplist 2
3. Multiple option Question

Droplist 2 if filtered by Droplist2
Multiple options question (checkboxes) is filtered by Droplist2.

Its very necessary cause Multiple options question has 1240 subquestions, I cant show them all...I have to filter them with dropdown2..

Is it possible to adapt the selectFilter.js to multiple options aswell?

Thank you so much
Der Administrator hat öffentliche Schreibrechte deaktiviert.

Re: Dropdownlist as a subquestion depending on first dropdown question 1 Jahr 1 Monat her #98043

  • holch
  • holchs Avatar
  • OFFLINE
  • LimeSurvey Team
  • Beiträge: 2622
  • Dank erhalten: 307
  • Karma: 113
Hmmm, and with 1240 subquestions for a multiple options question (which creates one column per subquestion) you don't run into database limits?
Have a look at the manual! It is a really valuable source for information. Here some helpful links:
Manual (EN) | Question Types | Question Attributes | Workarounds

If you found this answer helpful and it saved you some time please consider a donation to the project to keep Limesurvey going!
Der Administrator hat öffentliche Schreibrechte deaktiviert.

Re: Dropdownlist as a subquestion depending on first dropdown question 1 Jahr 1 Monat her #98044

  • Mazi
  • Mazis Avatar
  • OFFLINE
  • LimeSurvey Team
  • Beiträge: 5324
  • Dank erhalten: 294
  • Karma: 248
How many items are there at DD list 1/2 and the multiple choice question?

Maybe using some hidden questions and a (cascading) array filter might also do the trick.

Best regards/Beste Grüße,
Dr. Marcel Minke
(Limesurvey Head of Support)
Need Help? We offer professional Limesurvey support
Contact: marcel.minke(at)limesurvey.org'"
Letzte Änderung: 1 Jahr 1 Monat her von Mazi.
Der Administrator hat öffentliche Schreibrechte deaktiviert.

Re: Dropdownlist as a subquestion depending on first dropdown question 1 Jahr 1 Monat her #98051

  • Gabriela
  • Gabrielas Avatar
  • OFFLINE
  • Senior Lime
  • Beiträge: 64
  • Karma: 0
Hi all,
thanks so much for answering. Im attaching the survey, plus the .js code.
I dont know if there is a data base limit. I guess not, cause Ive told them about this and they said no problem...
Its on monitoring some activities in the south of Africa, and they want to have statistics on localities visited. So:
dropdown1= provinces
dropdown2= districts
Multiplechoice= localities (which can be several, thats why multiple choice)
I thought this code (used to filter the 2 dropdown ) could do, but its high level java for me. Im not at all javascript expert (or anything lower than that)

Thank you very much again.

/* 
Copyright 2012 Denis Chenu for <http://www.sondages.pro>
 
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:
 
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
 
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
/* Function to filter a select by another select 
   In the same page
   var qID : the number of question to filter 
   var filterqID : the number of question filtering
*/
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($("#"+idSelectFilter).width());*/
      $("#"+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());
		$('#'+idSelectFilter).trigger('change');
      });
 
      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());
        }
      }
    }
  });
}
function selectFilterDualScale(qID){
  $(document).ready(function(){
    if($("#question"+qID).hasClass('array-flexible-duel-scale')){
      // Fix width of columns
      answertextwidth=$(this).find("col.answertext").attr('width').replace("%","");
      $(this).find("col.ddarrayseparator").attr('width',"2%");
      ddarrayseparatorwidth=$(this).find("col.ddarrayseparator").attr('width').replace("%","");
      var newwidth=(100-answertextwidth*1-ddarrayseparatorwidth*1)/2;
      $(this).find("col.dsheader").attr('width',newwidth+'%');
      $("#question"+qID+" table.question tbody tr").each(function(index){
        $(this).find("select").each(function(){
          //$(this).attr('id',$(this).attr('id').replace('#',"_"));
        });
        var idSelectFiltering = jqSelector($(this).find("select").eq(0).attr('id'));
        var idSelectFilter = jqSelector($(this).find("select").eq(1).attr('id'));
        var idNewSelectFilter = jqSelector('select'+qID+'_'+index);
        var NewSelectElement = "<select id='"+idNewSelectFilter+"'><option value=''>"+$("#"+idSelectFilter+" option[value='']:first").text()+"</option></select>";
        $("#"+idSelectFilter).hide();
        $("#"+idSelectFilter).after(NewSelectElement);
        $("#"+idNewSelectFilter).width($("#"+idSelectFilter).width());
 
        $("#"+idSelectFiltering).change(function(){
          $("#"+idSelectFilter).val('');
          $('#'+idNewSelectFilter).val('');
          var valuefilter=$(this).val().substring(0, $(this).val().length - 2);
          $('#'+idNewSelectFilter+' option').not(':first').remove();
          if($(this).val()==""){
            $('#'+idNewSelectFilter).hide();
          }else{
            $('#'+idNewSelectFilter).show();
            $("#"+idSelectFilter).find('option').each(function(){
              if($(this).attr('value').substring(0, $(this).attr('value').length - 2)==valuefilter){
                $(this).clone().appendTo('#'+idNewSelectFilter);
              }
            });
          }
 
        });
        $("#"+idNewSelectFilter).change(function(){
          $('#'+idSelectFilter).val($(this).val());
		  $('#'+idSelectFilter).trigger('change');
          saveval=$('#'+idSelectFiltering).val();
          $('#'+idSelectFilter).trigger('change');
          if($(this).val()==""){
            $('#'+idSelectFiltering).val(saveval);
            $('#'+idSelectFiltering).trigger('change');
            $('#'+idSelectFilter).val($(this).val(""));
          }
        });
 
        if($("#"+idSelectFiltering).val()!=''){
          var valuefilter=$("#"+idSelectFiltering).val().substring(0, $("#"+idSelectFiltering).val().length - 2);
          $('#'+idSelectFilter+' option').each(function(){
            if($(this).attr('value').substring(0, $(this).attr('value').length - 2)==valuefilter){
              $(this).clone().appendTo('#'+idNewSelectFilter);
            }
          });
 
          if($("#"+idSelectFilter).val()!=''){
             $('#'+idNewSelectFilter).val($("#"+idSelectFilter).val());
          }
        }else{
           $('#'+idNewSelectFilter).hide();
        }
      });
    }
  });
}
function jqSelector(str)
{
    return str.replace(/([;&,\.\+\*\~':"\!\^#$%@\[\]\(\)=>\|])/g, '\\$1');
}
Letzte Änderung: 1 Jahr 1 Monat her von DenisChenu. Begründung: Use code balise PLEASE !
Der Administrator hat öffentliche Schreibrechte deaktiviert.

Re: Dropdownlist as a subquestion depending on first dropdown question 1 Jahr 1 Monat her #98053

  • DenisChenu
  • DenisChenus Avatar
  • ONLINE
  • Moderator Lime
  • Beiträge: 6272
  • Dank erhalten: 800
  • Karma: 240
Hello,

This JS is not for multi choice question type, only for select single choice.

But here, i really think you need to review complete system : you can't have 1240 sub question, a really bad idea.

I think you need : 2 select like actually , and one text question type.

For the text question type :
Use some ajax source : ivaynberg.github.io/select2/index.html#ajax
Use tag system : ivaynberg.github.io/select2/index.html#tags

Dut need another script here.

Denis
Der Administrator hat öffentliche Schreibrechte deaktiviert.
Moderatoren: ITEd
Ladezeit der Seite: 0.194 Sekunden
Donation Image