Welcome, Guest
Username: Password: Remember me
  • Page:
  • 1
  • 2

TOPIC: Dropdownlist as a subquestion depending on first dropdown question

Dropdownlist as a subquestion depending on first dropdown question 2 years 6 months ago #98037

  • Gabriela
  • Gabriela's Avatar
  • Offline
  • Senior Lime
  • Posts: 64
  • Thank you received: 1
  • 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
The administrator has disabled public write access.

Dropdownlist as a subquestion depending on first dropdown question 2 years 6 months ago #98043

  • holch
  • holch's Avatar
  • Offline
  • LimeSurvey Team
  • Posts: 4351
  • Thank you received: 612
  • Karma: 195
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!
The administrator has disabled public write access.

Dropdownlist as a subquestion depending on first dropdown question 2 years 6 months ago #98044

  • Mazi
  • Mazi's Avatar
  • Offline
  • LimeSurvey Team
  • Posts: 5836
  • Thank you received: 347
  • Karma: 261
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'"
Last Edit: 2 years 6 months ago by Mazi.
The administrator has disabled public write access.

Dropdownlist as a subquestion depending on first dropdown question 2 years 6 months ago #98051

  • Gabriela
  • Gabriela's Avatar
  • Offline
  • Senior Lime
  • Posts: 64
  • Thank you received: 1
  • 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');
}
Last Edit: 2 years 6 months ago by DenisChenu. Reason: Use code balise PLEASE !
The administrator has disabled public write access.

Dropdownlist as a subquestion depending on first dropdown question 2 years 6 months ago #98053

  • DenisChenu
  • DenisChenu's Avatar
  • Offline
  • Moderator Lime
  • Posts: 8195
  • Thank you received: 1117
  • Karma: 331
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
The administrator has disabled public write access.

Dropdownlist as a subquestion depending on first dropdown question 2 years 6 months ago #98059

  • holch
  • holch's Avatar
  • Offline
  • LimeSurvey Team
  • Posts: 4351
  • Thank you received: 612
  • Karma: 195
Overall I think the number of subquestions might be a problem, because there are certain limits on the number of columns in a MySQL database (like for most other database engines as well). And as you probably have more questions than this multiple choice question with 1240 subquestions, I think you will easily hit those limits.

First of all, the system with the two dropdowns will only work, if the person only has activities in one district of one province.

I don't know how many provinces do exist and how many districts a province has. I assume it is not an option to create different questions for each province and then for each district which will be shown by conditions. But anyway, this will still not solve the problem of many, many columns in the database table.

And by the way: Who are "they" who said this will not be a problem?
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!
The administrator has disabled public write access.
The following user(s) said Thank You: DenisChenu

Dropdownlist as a subquestion depending on first dropdown question 2 years 6 months ago #98060

  • Mazi
  • Mazi's Avatar
  • Offline
  • LimeSurvey Team
  • Posts: 5836
  • Thank you received: 347
  • Karma: 261
holch wrote:
Overall I think the number of subquestions might be a problem, because there are certain limits on the number of columns in a MySQL database (like for most other database engines as well). And as you probably have more questions than this multiple choice question with 1240 subquestions, I think you will easily hit those limits.
I agree. Before continuing, I recommend to activate the survey for testing to see if you run into the DB table limit.

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'"
The administrator has disabled public write access.

Dropdownlist as a subquestion depending on first dropdown question 2 years 6 months ago #98072

  • Gabriela
  • Gabriela's Avatar
  • Offline
  • Senior Lime
  • Posts: 64
  • Thank you received: 1
  • Karma: 0
HI all,
Thanks to all for answering.
I understand, "they" means the guys in charge of the IT department of the organization. (its an NGO). I activated the survey, and did nto show any error.
But reading all of your comments, I supose my solution is not an option then especially because of the number of items.
Than I should choose a Multiple text question?
I prefered multiple choice cause actually there is not a fixed number of localities they visit per period, so its difficult to guess how many fields to add to the multiple text question...
Any ideas how to solve this, I really appreciate it.
Thank you so much again
gab
The administrator has disabled public write access.

Dropdownlist as a subquestion depending on first dropdown question 2 years 6 months ago #98073

  • Gabriela
  • Gabriela's Avatar
  • Offline
  • Senior Lime
  • Posts: 64
  • Thank you received: 1
  • Karma: 0
Sorry,
when I tested in local it gave no error.
But in the server it did.

"[an error occurred while processing this directive]"

So definitely there would be a DB problem.

thanks..
The administrator has disabled public write access.

Dropdownlist as a subquestion depending on first dropdown question 2 years 6 months ago #98076

  • DenisChenu
  • DenisChenu's Avatar
  • Offline
  • Moderator Lime
  • Posts: 8195
  • Thank you received: 1117
  • Karma: 331
Hello,

With selectjs : i don't tal af a multi text bur a long text.

The city is savec in DB like that:
city1,city2,city2

Denis
The administrator has disabled public write access.

Dropdownlist as a subquestion depending on first dropdown question 2 years 3 months ago #101289

  • dweisser
  • dweisser's Avatar
  • Offline
  • Gold Lime
  • Posts: 210
  • Thank you received: 5
  • Karma: 5
This solution is fantastic. Cascading selection FTW!

One question, when I put the function in the template.js, the cascading between drop-downs no longer works. Both parts of the script seem to have to be in the source of the questiontext of the second, or dependent, question.

I was only wondering why this is the case. Seems to me you should be able to put the first part into the template.js.

Thank you again for a really great piece of work!
David
The administrator has disabled public write access.

Dropdownlist as a subquestion depending on first dropdown question 2 years 3 months ago #101337

  • DenisChenu
  • DenisChenu's Avatar
  • Offline
  • Moderator Lime
  • Posts: 8195
  • Thank you received: 1117
  • Karma: 331
Hi,

Think we can copy/paste all js file on template.js, but maybe lost something. And the scrpt was made for 1.92, not updated actually for 2.00.

Do you have a link to test ?

Denis
The administrator has disabled public write access.

Dropdownlist as a subquestion depending on first dropdown question 2 years 2 months ago #101625

  • dweisser
  • dweisser's Avatar
  • Offline
  • Gold Lime
  • Posts: 210
  • Thank you received: 5
  • Karma: 5
I think the template.js issue was taken care of by a recent update.

But, on a related question. I'm trying to accomplish something like one of the earlier posters:
List 3 is dependent on List 2 and List 2 is Dependent on List 1.

List 1 to List 2 works just fine. But List 2 to List 3 doesn't work at all. No answers show.
It seems to me that all it it should require is to repeat the process for each dependent question, but alas...

Here is a test link: http://www.springboltconsulting.com/survey/index.php

Any insight you can can provide would be most appreciated - as always.

Nebraska David
The administrator has disabled public write access.
  • Page:
  • 1
  • 2
Moderators: ITEd
Time to create page: 0.555 seconds