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
  • ColinBrose's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
7 years 1 month ago #158559 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
The topic has been locked.
More
6 years 6 months ago #167155 by AWGAWG
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
  • Joffm's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
6 years 6 months ago - 6 years 6 months ago #167158 by Joffm
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

Volunteers are not paid.
Not because they are worthless, but because they are priceless
Last edit: 6 years 6 months ago by Joffm.
The topic has been locked.
Moderators: tpartnerholch

Lime-years ahead

Online-surveys for every purse and purpose