Welcome to the LimeSurvey Community Forum

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

Array question with answers in dropdown boxes

More
10 years 10 months ago - 10 years 10 months ago #113827 by tpartner
Ah, in pre-2.05 versions the text inputs were placed inside the labels, which was poorly formed HTML. Now they are siblings of the labels.

Change this line:
Code:
$('#question'+qID+' .answer_cell_004 input[type="text"]').hide().parent().hide();

To this:
Code:
$('#question'+qID+' .answer_cell_004 input[type="text"]').hide();

So, the complete code:
Code:
<script type="text/javascript" charset="utf-8">
  $(document).ready(function() {
 
    var qID = {QID};
 
    // Define the select element (dropdown)
    var select1 = '<select class="insertedSelect">\
          <option value="">-- Please Choose --</option>\
          <option value="Nuevo">Nuevo</option>\
          <option value="Reparado">Reparado</option>\
          <option value="Deteriorado">Deteriorado</option>\
          <option value="Inservible">Inservible</option>\
        </select>';
 
    // Hide the text inputs
    $('#question'+qID+' .answer_cell_004 input[type="text"]').hide();
 
    // Insert the select elements
    $('#question'+qID+' .answer_cell_004').append(select1);
 
    // Initially select an option if the question has already been answered
    $('#question'+qID+' .answer_cell_004 input[type="text"]').each(function(i){
      if($(this).val()) {
        $(this).closest('td').find('.insertedSelect').val($(this).val());
      }
    });
 
    // Listener on the dropdowns - insert selected values into hidden text input
    $('.insertedSelect').change(function() {
      $(this).closest('td').find('input[type="text"]').val($(this).val());
    });
  });
</script>

Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
Last edit: 10 years 10 months ago by tpartner.
The topic has been locked.
More
9 years 3 months ago #137890 by Juanoche
Hello,
I'm using versión Versión 2.50+ Build 160526 and this script don't work for me (spanish survey). Any help is apreciated..

<script type="text/javascript" charset="utf-8">

$(document).ready(function(){

$('#question298 .answer_cell_00SQ001 option[value=1]').text('No recurro');
$('#question298 .answer_cell_00SQ001 option[value=2]').text('Arocena Gustavo');
$('#question298 .answer_cell_00SQ001 option[value=3]').text('Aspra Manuel');
$('#question298 .answer_cell_00SQ001 option[value=4]').text('Bravo Ricardo');
$('#question298 .answer_cell_00SQ001 option[value=5]').text('Zalazar Martin');

$('#question298 .answer_cell_00SQ002 option[value=1]').text('No recurro');
$('#question298 .answer_cell_00SQ002 option[value=2]').text('Bravo Ricardo');
$('#question298 .answer_cell_00SQ002 option[value=3]').text('Fernandez Flavio');
$('#question298 .answer_cell_00SQ002 option[value=4]').text('Zalazar Martin');
$('#question298 .answer_cell_00SQ002 option[value=5]').text('').hide();

});

</script>
The topic has been locked.
More
9 years 3 months ago #137914 by tpartner
I'm not sure you have correct jQuery selectors. If, for example, you have x-scale subquestion codes X1 and X2, the code should look like this (no need to replace {QID}):

Code:
<script type="text/javascript" charset="utf-8">    
  $(document).ready(function(){
    $('#question{QID} .answer_cell_X1 option[value=1]').text('No recurro');
    $('#question{QID} .answer_cell_X1 option[value=2]').text('Arocena Gustavo');
    $('#question{QID} .answer_cell_X1 option[value=3]').text('Aspra Manuel');
    $('#question{QID} .answer_cell_X1 option[value=4]').text('Bravo Ricardo');
    $('#question{QID} .answer_cell_X1 option[value=5]').text('Zalazar Martin');
 
    $('#question{QID} .answer_cell_X2 option[value=1]').text('No recurro');
    $('#question{QID} .answer_cell_X2 option[value=2]').text('Bravo Ricardo');
    $('#question{QID} .answer_cell_X2 option[value=3]').text('Fernandez Flavio');
    $('#question{QID} .answer_cell_X2 option[value=4]').text('Zalazar Martin');
    $('#question{QID} .answer_cell_X2 option[value=5]').remove();
  });
</script>

Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
The topic has been locked.
More
9 years 3 months ago #137923 by DenisChenu
Hi,

Actually for such solution : you have a plugin : www.limesurvey.org/forum/plugins/104019-...ith-dropdwon-or-mask

It work on a 2.50 last time i tested.

Assistance on LimeSurvey forum and LimeSurvey core development are on my free time.
I'm not a LimeSurvey GmbH member. - Professional support - Plugins, theme and development .
I don't answer to private message.
The topic has been locked.
More
9 years 2 months ago #137950 by Juanoche

tpartner wrote: I'm not sure you have correct jQuery selectors. If, for example, you have x-scale subquestion codes X1 and X2, the code should look like this (no need to replace {QID})

Tony thanks for showing me the light. I was writting y-scale subquestion codes...
The topic has been locked.
More
9 years 2 months ago #137951 by Juanoche

DenisChenu wrote: Hi,

Actually for such solution : you have a plugin : www.limesurvey.org/forum/plugins/104019-...ith-dropdwon-or-mask

It work on a 2.50 last time i tested.


DenisChenu I had already seen that plugin but unfortunately I get a 500 error on my server when I install it and try to acces survey settings / Plugins
The topic has been locked.
More
9 years 2 months ago #137953 by DenisChenu

Juanoche wrote:

DenisChenu wrote: Hi,

Actually for such solution : you have a plugin : www.limesurvey.org/forum/plugins/104019-...ith-dropdwon-or-mask

It work on a 2.50 last time i tested.


DenisChenu I had already seen that plugin but unfortunately I get a 500 error on my server when I install it and try to acces survey settings / Plugins

See github.com/SondagesPro/LS-arrayTextAdapt...suecomment-223626556

I can not reproduce the issue : then need tester.

Assistance on LimeSurvey forum and LimeSurvey core development are on my free time.
I'm not a LimeSurvey GmbH member. - Professional support - Plugins, theme and development .
I don't answer to private message.
The topic has been locked.
More
8 years 10 months ago #143401 by ramzus
Hi tpartner,

I used this solution and it was very helpful, but now i want to show the selected dropdown text in the next question but the Limesurvey replacement field properties shown only the code selected.

Thanks
The topic has been locked.
More
8 years 10 months ago #143406 by tpartner
Err...which solution. There are many in this thread, some of which are years old. It may be better to start a new thread describing exactly what you did and the details of your LimeSurvey environment.

Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
The topic has been locked.
More
8 years 10 months ago #143413 by ramzus
The solution for the array question with text answers in a dropdown box i want to show the selected dropdown text in the next question but the Limesurvey replacement field properties shown only the code selected.
Code:
<script type="text/javascript" charset="utf-8">
 
  $(document).ready(function(){
 
        $('#questionQQ .answer_cell_001 option[value=1]').text('No recurro');
        $('#questionQQ .answer_cell_001 option[value=2]').text('Arocena Gustavo');
        $('#questionQQ .answer_cell_001 option[value=3]').text('Aspra Manuel');
        $('#questionQQ .answer_cell_001 option[value=4]').text('Bravo Ricardo');
        $('#questionQQ .answer_cell_001 option[value=5]').text('Zalazar Martin');
 
        $('#questionQQ .answer_cell_002 option[value=1]').text('No recurro');
        $('#questionQQ .answer_cell_002 option[value=2]').text('Bravo Ricardo');
        $('#questionQQ .answer_cell_002 option[value=3]').text('Fernandez Flavio');
        $('#questionQQ .answer_cell_002 option[value=4]').text('Zalazar Martin');
        $('#questionQQ .answer_cell_002 option[value=5]').text('').hide();
 
    });
The topic has been locked.
More
8 years 10 months ago #143424 by tpartner
In that case, you would either need to use Expression Manager to pipe in the text depending on the code or use Denis' arrayTextAdapt plugin .

Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
The topic has been locked.
More
8 years 10 months ago #143436 by ramzus
Thank you very much, i will try this
The topic has been locked.
More
7 years 2 months ago #170145 by b1994mi
Hi,

I have been using tpartner's javascript for providing dropdown options on array (texts). But, now I need something a bit specific. I need to make certain row readonly and force an answer that is different from the options provided by the dropdown.

What the respondents will think is that this readonly inputs are fixed because they need to use MRT for that journey.

Here is the mockup of what I need:
Warning: Spoiler!


I have attached my survey file with only the corresponding question group.
More
7 years 2 months ago #170227 by tpartner
I don't think it's possible with a single array question as your "MRT" row is a moving target depending on the answers to the first two questions. I would do it with three array questions, styled with CSS to appear as one.

- One array for modes getting to MRT
- One (readonly) array for MRT
- One array for modes getting from MRT

Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
The topic has been locked.
More
7 years 2 months ago #170232 by b1994mi
Hi,

I have found this thread and it is about two radio button question merged into one.

How to call the previous question? (assuming that I place the MRT in the middle)

Or is there any exact thread you can refer? It is a bit too complicated for me to implement the CSS :(

Thank you in advance.
The topic has been locked.
Moderators: tpartnerholch

Lime-years ahead

Online-surveys for every purse and purpose