Array question with answers in dropdown boxes

More
6 years 2 months ago #58190 by Usapuka
Usapuka created the topic: Array question with answers in dropdown boxes
Hi,How can I do an array question with text answers in a dropdown box?
Thank you,

Please Log in to join the conversation.

More
6 years 2 months ago #58217 by tpartner
tpartner replied the topic: Array question with answers in dropdown boxes

Cheers,
Tony Partner
Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
The following user(s) said Thank You: Usapuka

Please Log in to join the conversation.

More
6 years 2 months ago #58235 by Usapuka
Usapuka replied the topic: Array question with answers in dropdown boxes
tpartner,

Thank you for your answer.
Sorry, I'm just beginning with LimeSurvey and I don't know much of javascript, so please excuse me, my first trial of the solution was a completed failure...
What I like to do is this (is in Spanish but can get the idea): http://tecnobiz.com.ar/Surveys/Oldelval/referentes
It is possible?

Thank you again!

Please Log in to join the conversation.

More
6 years 2 months ago #58244 by tpartner
tpartner replied the topic: Array question with answers in dropdown boxes
Ah, part of the problem is that you want different dropdowns in the same question.

To reproduce the first question in your example survey:

1) Set up your survey to use JavaScript .

2) Create an Array (Numbers) question with a minimum value of 1 and a maximum value of 5.

3)Add your x-scale and y-scale subquestions

4) Add the following script to the source of the array question. Replace "QQ" with the array question ID.

As stated in the referenced forum post, the replacement text in the dropdowns will not be stored in the data - you will need to map to it in post-survey analysis.
<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();
 
    });
 
</script>

Cheers,
Tony Partner
Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
The following user(s) said Thank You: Usapuka

Please Log in to join the conversation.

More
6 years 2 months ago #58286 by Usapuka
Usapuka replied the topic: Array question with answers in dropdown boxes
Tony,
Thank you for your explanation, I did what you told me but something is wrong... I still see the numbers instead of the text. Here I send you the question I did: please, can you take a look to it?
Thank you, Gabriel

File Attachment:

File Name: limesurvey..._298.lsq
File Size:8 KB
Attachments:

Please Log in to join the conversation.

More
6 years 2 months ago #58296 by tpartner
tpartner replied the topic: Array question with answers in dropdown boxes
It seems that the cell classes are different in Spanish (and presumably other languages).

Try this:
<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>

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

Please Log in to join the conversation.

More
6 years 2 months ago #58319 by Usapuka
Usapuka replied the topic: Array question with answers in dropdown boxes
Hi Tony,

Thank you very much. Now is working :cheer:

Best regards from Buenos Aires!

Please Log in to join the conversation.

More
4 years 1 month ago #94880 by ricardo01
ricardo01 replied the topic: Array question with answers in dropdown boxes
Tony,

how can I create drop-drown lists with different number of items? for instance, 50 options for the first column, 10 for the second, and 5 for the third? This is what my test looks right now...



But I only want 6 options in column 3.

Thanks you

ricardo
Attachments:

Please Log in to join the conversation.

More
4 years 1 month ago #94885 by ricardo01
ricardo01 replied the topic: Array question with answers in dropdown boxes
Also, how can I use the apostrophe in the text in parentheses. When I use something like this (note King's college), the dropdown list doesn't show up.

$('#question174 .answer_cell_001 option[value=135]').text('King's College London');

But if I remove the apostrophe and just leave it as ('Kings College London'); it works fine.

Please Log in to join the conversation.

More
4 years 1 month ago #94888 by Mazi
Mazi replied the topic: Array question with answers in dropdown boxes
1. Please post your Javascript and attach the question as LSQ file.

2. To escape the apostrophe, try ...King\'s College London...:
$('#question174 .answer_cell_001 option[value=135]').text('King\'s College London');

Alternatively, use quotes at the JavaScript so the apostrophe doesn't influence the quoting.


Best regards/Beste Grüße,
Dr. Marcel Minke
(Limesurvey Head of Support)
Need Help? We offer professional Limesurvey support
Contact: marcel.minke(at)survey-consulting.com'"

Please Log in to join the conversation.

More
4 years 1 month ago - 4 years 1 month ago #94907 by ricardo01
ricardo01 replied the topic: Array question with answers in dropdown boxes

File Attachment:

File Name: dropdown.txt
File Size:27 KB

Thank you Mazi,

attached find the java script and the question in .lsq format. Again, in columns 2 and 3 I have fewer items than in column 1, so I'd like to get rid of those extra numbers.




Thanks for your help


File Attachment:

File Name: dropdownquestion.lsq
File Size:34 KB


File Attachment:

File Name: dropdown.txt
File Size:27 KB
Attachments:
Last Edit: 4 years 1 month ago by ricardo01. Reason: attach file

Please Log in to join the conversation.

More
4 years 1 month ago #94926 by ricardo01
ricardo01 replied the topic: Array question with answers in dropdown boxes
I think I almost got it. I hid the text for the items I don't need. However, when I paste and save the javascript in the question source, the code breaks around line 847. Is there a limited amount of text that can be saved in the question source?

This is what I paste




and this is what is saved




This is my updated javascript

File Attachment:

File Name: dropdown_2...4-15.txt
File Size:69 KB





Thanks in advance for your help
Attachments:

Please Log in to join the conversation.

More
4 years 1 month ago #94931 by tpartner
tpartner replied the topic: Array question with answers in dropdown boxes
Dunno why that's being truncated but you should be able to replace all of those lines with a simple loop.

Replace all of the lines like this:
$('#question174 .answer_cell_003 option[value=6]').text('').hide();


With this block:
$('#question174 .answer_cell_003 option').each(function(i){
	if($(this).val() > 5) {
		$(this).remove();
	}
});

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

Please Log in to join the conversation.

More
4 years 1 month ago #94937 by ricardo01
ricardo01 replied the topic: Array question with answers in dropdown boxes
Thanks Tony! It worked for this example.

I need to create a similar question listing US universities (n=3492)...my javascript has 3983 lines. The problem is that when I paste it in the question source, it gets truncated around line 695.

is there a way to solve this?

ricardo

Please Log in to join the conversation.

More
4 years 1 month ago #94940 by tpartner
tpartner replied the topic: Array question with answers in dropdown boxes
Try removing the script from the question source and place it at the end of template.js

Remove the opening script tag:
<script charset="utf-8" type="text/javascript">
And the closing script tag:
</script>

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

Please Log in to join the conversation.

Start now!

Just create your account and start using Limesurvey today.

Register now