List dropdown in multiple short text question

More
2 months 4 weeks ago #158559 by ColinBrose
ColinBrose created the topic: List dropdown in multiple short text question
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

Please Log in to join the conversation.

Start now!

Just create your account and start using Limesurvey today.

Register now
Join our Newsletter!