Welcome, Guest
Username: Password: Remember me

TOPIC: 2 side by side questions

2 side by side questions 8 months 2 weeks ago #98708

  • gatinc
  • gatinc's Avatar
hi,

I have used default template on 2.0. How can I add 2 side by side questions? and I want to use one wrap.

Can you help me in this problem?
The administrator has disabled public write access.

2 side by side questions 8 months 2 weeks ago #98720

  • tpartner
  • tpartner's Avatar
  • OFFLINE
  • LimeSurvey Team
  • Posts: 3813
  • Thank you received: 683
  • Karma: 328
Can you attach a sample survey and a screenshot of what questions you want side-by-side?
Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.

LimeSurvey is open-source and run entirely by volunteers so please consider donating to support the project.
The administrator has disabled public write access.

2 side by side questions 8 months 2 weeks ago #98740

  • gatinc
  • gatinc's Avatar
Hi,

I found solition on yours old messages. Now, I have new problem!

I used the following code for side by side question and selectfilter.js. Its worked good. But it was added to the second answer for second question. You can see in the attached picture.

Attachment Untitled.jpg not found



<script type="text/javascript" charset="utf-8">
 
 $(document).ready(function() {
 
 // Call the function wit the start and end question positions
 sideBySide(1, 2);
 
 function sideBySide(start, end) {
 
 // Add some temporary classes to the target questions
 $('div[id^="question"]').each(function(i){
 var qNum = i + 1;
 var el = $(this);
 if (qNum >= start && qNum <= end) {
 $(el).addClass('targetQ');
 }
 });
 
 // Wrap the questions in a div
 $('.targetQ').wrapAll('<div class="targetWrapper" />');
 $('.targetWrapper').after('<div style="clear:both" />');
 
 // Add some classes to the questions in the target wrapper
 $('.targetWrapper .targetQ').addClass('inlineQuestion inlineQuestionSub');
 $('.targetWrapper .inlineQuestionSub:first').removeClass('inlineQuestionSub').addClass('inlineQuestionPrime');
 
 // Remove the text from the secondary questions
 $('.targetWrapper .inlineQuestionSub th.answertext').text('');
 
 // Apply some styles (these are for the default template)
 $('.targetWrapper .inlineQuestion').css({ 'float': 'left' });
 $('.targetWrapper .inlineQuestion col, .targetWrapper .inlineQuestion th.answertext').css({ 'width': 'auto' });
 $('.targetWrapper .inlineQuestion .question-wrapper').css({ 'width': '354px' });
 $('.targetWrapper .inlineQuestion td.answer').css({ 'padding': '0.5em 0' });
 $('.targetWrapper .inlineQuestion td.questiontext').css({ 'text-align': 'left' });
 
 // Center the wrapper div
 var wrapperWidth = 0;
 $('.targetWrapper .inlineQuestion').each(function(i){
 wrapperWidth = wrapperWidth + $(this).width();
 var padLeft = $('.answertext:eq(0)', this).width() + 12;
 $('.questiontext', this).css({ 'padding-left':padLeft+'px', 'padding-right':'3px' });
 });
 $('.targetWrapper').css({ 'width':wrapperWidth+'px', 'margin': '0 auto' });
 
 // Set the row heights
 var wrapperWidth = 0;
 $('.targetWrapper .inlineQuestionSub').each(function(i){
 $('tbody[id^="javatbd"]', this).each(function(i){
 var ansHeight = $('.targetWrapper .inlineQuestionPrime th.answertext:eq('+i+')').innerHeight();
 
 if($.browser.mozilla) {
 $('th.answertext', this).height(ansHeight-1);
 }
 else {
 $('th.answertext', this).innerHeight(ansHeight);
 }
 });
 });
 
 // Remove the temporary classes
 $('.targetQ').removeClass('targetQ');
 $('.targetWrapper').removeClass('targetWrapper');
 }
 });
 
 </script>
The administrator has disabled public write access.

2 side by side questions 8 months 2 weeks ago #98743

  • tpartner
  • tpartner's Avatar
  • OFFLINE
  • LimeSurvey Team
  • Posts: 3813
  • Thank you received: 683
  • Karma: 328
I have no idea what selectfilter.js is but I see nothing in that code to cause the problem.
Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.

LimeSurvey is open-source and run entirely by volunteers so please consider donating to support the project.
The administrator has disabled public write access.

2 side by side questions 8 months 2 weeks ago #98744

  • gatinc
  • gatinc's Avatar
Hi,
I'm sorry I forgot to add. You can see in the attached script.

I added this code to the second question.
<script type='text/javascript' src='{TEMPLATEURL}selectfilter.js'></script>
<script type="text/javascript" charset="utf-8">
selectFilterByCode({QID},1);
</script>

selectfilter.js
/* 
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());
          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: 8 months 2 weeks ago by gatinc.
The administrator has disabled public write access.

2 side by side questions 8 months 2 weeks ago #98750

  • tpartner
  • tpartner's Avatar
  • OFFLINE
  • LimeSurvey Team
  • Posts: 3813
  • Thank you received: 683
  • Karma: 328
Well, I can't really speak to someone else's plugin but it seems to me that selectFilterByCode() is not being used correctly.
Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.

LimeSurvey is open-source and run entirely by volunteers so please consider donating to support the project.
The administrator has disabled public write access.

2 side by side questions 8 months 2 weeks ago #98752

  • gatinc
  • gatinc's Avatar
Where is the problem? Can you help me in this problem? please.
The administrator has disabled public write access.
Moderators: ITEd
Time to create page: 0.347 seconds
Donation Image