- Posts: 2
- Thank you received: 0
Welcome to the LimeSurvey Community Forum
Ask the community, share ideas, and connect with other LimeSurvey users!
Array text with a Dropdown column
- leonardoas
- Topic Author
- Offline
- New Member
Less
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>
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
- Offline
- LimeSurvey Community Team
Less
More
- Posts: 10611
- Thank you received: 3690
8 years 10 months ago #120502
by tpartner
Cheers,
Tony Partner
Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
Replied by tpartner on topic Array text with a Dropdown column
Change these lines:
To this:
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
- Topic Author
- Offline
- New Member
Less
More
- Posts: 2
- Thank you received: 0
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.
- jph123
- Offline
- New Member
Less
More
- Posts: 10
- Thank you received: 0
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>
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
- Offline
- LimeSurvey Community Team
Less
More
- Posts: 10611
- Thank you received: 3690
8 years 9 months ago #121054
by tpartner
Cheers,
Tony Partner
Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
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.
- jph123
- Offline
- New Member
Less
More
- Posts: 10
- Thank you received: 0
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.
Thanks for your help.
John
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.
Thanks for your help.
John
Attachments:
The topic has been locked.
- tpartner
- Offline
- LimeSurvey Community Team
Less
More
- Posts: 10611
- Thank you received: 3690
8 years 9 months ago #121067
by tpartner
Cheers,
Tony Partner
Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
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.
- jph123
- Offline
- New Member
Less
More
- Posts: 10
- Thank you received: 0
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
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
- Offline
- LimeSurvey Community Team
Less
More
- Posts: 10611
- Thank you received: 3690
8 years 9 months ago #121099
by tpartner
Cheers,
Tony Partner
Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
Replied by tpartner on topic Array text with a Dropdown column
A couple of problems...
You have a JavaScript error. This line:
Sould be:
You have used the wrong selector for the array cells. All instances of this:
Should be:
You have a JavaScript error. This line:
Code:
var qID = {qID};
Code:
var qID = {QID};
You have used the wrong selector for the array cells. All instances of this:
Code:
.answer_cell_001
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.