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