Welcome to the LimeSurvey Community Forum

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

Array text with a Dropdown column

  • leonardoas
  • leonardoas's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
8 years 10 months ago #120489 by leonardoas
Array text with a Dropdown column was created by leonardoas
Does anyone know how to insert a text array and a column to be the Dropdown type?

I used this feature to last year, but it seems that after upgrading from Limesurvey stopped working. Follows the code.


2.1 Indique o tipo de evento, nome do evento e instituição, nome do artista e tipo de apoio:


<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="">-- Selecione o tipo de evento --</option> \
<option value="1">Exposição institucional coletiva</option> \
<option value="2">Exposição institucional individual</option> \
<option value="3">Exposição coletiva em galeria comercial</option> \
<option value="4">Exposição individual em galeria comercial</option> \
<option value="5">Residência</option> \
</select>';

// Hide the text inputs
$('#question'+qID+' .answer_cell_004 input[type="text"]').hide().parent().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>
The topic has been locked.
  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
8 years 10 months ago #120502 by tpartner
Replied by tpartner on topic Array text with a Dropdown column
Change these lines:
Code:
// Hide the text inputs
$('#question'+qID+' .answer_cell_004 input[type="text"]').hide().parent().hide();

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

Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
The topic has been locked.
  • leonardoas
  • leonardoas's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
8 years 10 months ago #120610 by leonardoas
Replied by leonardoas on topic Array text with a Dropdown column
Perfect! Thank you very much .
The topic has been locked.
More
8 years 9 months ago #121049 by jph123
Replied by jph123 on topic Array text with a Dropdown column
Hi, I'm trying to do the same thing with a three column array (want the first column to be a drop down) but this code doesn't seem to work for me. What am I doing wrong? (using the latest limesurvey version.)

Please specify your room requirements: <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="">-- Select Room Type --</option> \
<option value="1">Single</option> \
<option value="2">Twin</option> \
<option value="3">Disabled</option> \
</select>';

// Hide the text inputs
$('#question'+qID+' .answer_cell_001 input[type="text"]').hide();

// Insert the select elements
$('#question'+qID+' .answer_cell_001').append(select1);

// Initially select an option if the question has already been answered
$('#question'+qID+' .answer_cell_001 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>
The topic has been locked.
  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
8 years 9 months ago #121054 by tpartner
Replied by tpartner on topic Array text with a Dropdown column
Please give us a link to a SMALL test survey so we can see the source and any JavaScript errors.

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 9 months ago #121060 by jph123
Replied by jph123 on topic Array text with a Dropdown column
Hi,

I've tried to send a link but it tells me that it considers it spam so I've exported and attached an example instead.

File Attachment:

File Name: limesurvey...3655.lss
File Size:19 KB



Thanks for your help.

John
The topic has been locked.
  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
8 years 9 months ago #121067 by tpartner
Replied by tpartner on topic Array text with a Dropdown column
Sorry, that doesn't help - it need to be in your environment. Can you post the link here?

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 9 months ago #121073 by jph123
Replied by jph123 on topic Array text with a Dropdown column
Hi,

Example as requested:

[url=http://http://surveys.englandnetball.co.uk/index.php/573655/lang-en]link[/url]

Thanks for your help.

John
The topic has been locked.
  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
8 years 9 months ago #121099 by tpartner
Replied by tpartner on topic Array text with a Dropdown column
A couple of problems...

You have a JavaScript error. This line:
Code:
var qID = {qID};
Sould be:
Code:
var qID = {QID};

You have used the wrong selector for the array cells. All instances of this:
Code:
.answer_cell_001
Should be:
Code:
.answer_cell_00SQ001

Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
The topic has been locked.

Lime-years ahead

Online-surveys for every purse and purpose