- Posts: 4
- Thank you received: 0
Welcome to the LimeSurvey Community Forum
Ask the community, share ideas, and connect with other LimeSurvey users!
List dropdown in multiple short text question
- ColinBrose
- Topic Author
- Offline
- New Member
Less
More
6 years 7 months ago #158559
by ColinBrose
List dropdown in multiple short text question was created by ColinBrose
Dear Limesurvey community,
I am currently creating a survey in which I intend to use a multiple short text question. Within that question, I would like to replace one short text box with a dropdown list. I thought that I had found what I was looking for in this post: www.limesurvey.org/forum/can-i-do-this-w...-multiple-short-text
The post told me to insert the following code into the source of the corresponding question:
<script type="text/javascript" charset="utf-8">
$(document).ready(function() {
var qID = {QID};
var inputNum = 4;
// Define the select element (dropdown)
var select1 = '<select id="select1"> \
<option value="">-- Please Choose --</option> \
<option value="Apples">Apples</option> \
<option value="Oranges">Oranges</option> \
<option value="Pears">Pears</option> \
<option value="Bananas">Bananas</option> \
</select>';
// Hide the text input
$('#question'+qID+' li:eq('+(inputNum-1)+') input.text').hide().parent().hide();
// Insert the select elements
$('#question'+qID+' li:eq('+(inputNum-1)+')').append(select1);
// Initially select an option if the question has already been answered
if($('#question'+qID+' li:eq('+(inputNum-1)+') input.text').val()) {
$('#question'+qID+' li:eq('+(inputNum-1)+') select').val($('#question'+qID+' li:eq('+(inputNum-1)+') input.text').val())
}
// Listener on the dropdowns - insert selected values into hidden text input
$('#question'+qID+' select').change(function() {
$(this).siblings('span').children('input.text').val($(this).val());
});
// Some styles
$('#question'+qID+' select').css({
'margin':'0.3em 0 0 1em'
});
});
</script>
As the post is 5 years old, clearly things must have changed and inserting the code yielded no result. I would be grateful for any helpful hints on how to insert the dropdown!
Thanks a lot,
Colin
using LimeSurvey Version 2.67.3
I am currently creating a survey in which I intend to use a multiple short text question. Within that question, I would like to replace one short text box with a dropdown list. I thought that I had found what I was looking for in this post: www.limesurvey.org/forum/can-i-do-this-w...-multiple-short-text
The post told me to insert the following code into the source of the corresponding question:
<script type="text/javascript" charset="utf-8">
$(document).ready(function() {
var qID = {QID};
var inputNum = 4;
// Define the select element (dropdown)
var select1 = '<select id="select1"> \
<option value="">-- Please Choose --</option> \
<option value="Apples">Apples</option> \
<option value="Oranges">Oranges</option> \
<option value="Pears">Pears</option> \
<option value="Bananas">Bananas</option> \
</select>';
// Hide the text input
$('#question'+qID+' li:eq('+(inputNum-1)+') input.text').hide().parent().hide();
// Insert the select elements
$('#question'+qID+' li:eq('+(inputNum-1)+')').append(select1);
// Initially select an option if the question has already been answered
if($('#question'+qID+' li:eq('+(inputNum-1)+') input.text').val()) {
$('#question'+qID+' li:eq('+(inputNum-1)+') select').val($('#question'+qID+' li:eq('+(inputNum-1)+') input.text').val())
}
// Listener on the dropdowns - insert selected values into hidden text input
$('#question'+qID+' select').change(function() {
$(this).siblings('span').children('input.text').val($(this).val());
});
// Some styles
$('#question'+qID+' select').css({
'margin':'0.3em 0 0 1em'
});
});
</script>
As the post is 5 years old, clearly things must have changed and inserting the code yielded no result. I would be grateful for any helpful hints on how to insert the dropdown!
Thanks a lot,
Colin
using LimeSurvey Version 2.67.3
The topic has been locked.
- AWGAWG
- Offline
- New Member
Less
More
- Posts: 3
- Thank you received: 0
6 years 2 weeks ago #167155
by AWGAWG
Replied by AWGAWG on topic List dropdown in multiple short text question
Reviving the thread since I'm experiencing the same problem: that code doesn't turn a short text field in a dropdown.
The topic has been locked.
- Joffm
- Offline
- LimeSurvey Community Team
Less
More
- Posts: 12940
- Thank you received: 3979
6 years 2 weeks ago - 6 years 2 weeks ago #167158
by Joffm
Volunteers are not paid.
Not because they are worthless, but because they are priceless
Replied by Joffm on topic List dropdown in multiple short text question
Hi,
the code of this post is originally 6 years old and about LS version 1.9x.
As Colin said, it doesn't work in the 2.50- branch and will not wortk in the 3.x branch.
So, better you stay to your other thread.
Joffm
the code of this post is originally 6 years old and about LS version 1.9x.
As Colin said, it doesn't work in the 2.50- branch and will not wortk in the 3.x branch.
So, better you stay to your other thread.
Joffm
Volunteers are not paid.
Not because they are worthless, but because they are priceless
Last edit: 6 years 2 weeks ago by Joffm.
The topic has been locked.