Welcome to the LimeSurvey Community Forum

Ask the community, share ideas, and connect with other LimeSurvey users!

Dropdown box in array

  • Maribelcarol
  • Maribelcarol's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
3 years 7 months ago #205317 by Maribelcarol
Dropdown box in array was created by Maribelcarol
Hi,
So I'd like to have dropdown boxes in an array. I have this script but I keep seeing the numbers in the dropdown. I just want to see the words. Could somebody help me with this?
Code:
<script type="text/javascript" charset="utf-8">
  $(document).on('ready pjax:scriptcomplete',function(){
    var thisQuestion = $('#question{QID}');
 
    // Insert selects
    $('.answer-item', thisQuestion).append('<select class="inserted-select form-control list-question-select">\
                          <option value="">Please choose...</option>\
<option value="1">Fraxinus spp.</option>\
<option value="2">Gleditsia triacanthos</option>\
<option value="3">Gymnocladus dioicus</option>\
<option value="4">Platanus x acerifolia</option>\
<option value="5">Thuja spp.</option>\
<option value="6">Ulmus spp</option>\
<option value="7">Celtis spp.</option>\
<option value="8">Gingkgo biloba</option>\
<option value="9">Pyrus spp.</option>\
  </select>'); 
 
 
    // Listeners
    $('.inserted-select', thisQuestion).on('change', function(i) {
      if($(this).val() != '') {
        $(this).closest('.answer-item').find('input:text').val($.trim($(this).val())).trigger('change');
      }
      else {
        $(this).closest('.answer-item').find('input:text').val('').trigger('change');
      }
    });
 
    // Returning to page
    $('input:text', thisQuestion).each(function(i) {
      var thisCell = $(this).closest('.answer-item');
      var inputVal = $.trim($(this).val());
      $('select.inserted-select', thisCell).val(inputVal);
    });
 
    // Clean-up styles
    $('select.inserted-select', thisQuestion).css({
      'max-width': '100%'
    });
    $('input:text', thisQuestion).css({
      'position': 'absolute',
      'left': '-9999em'
    });
  });
</script>




Thanks!
The topic has been locked.
  • Joffm
  • Joffm's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
3 years 7 months ago - 3 years 7 months ago #205322 by Joffm
Replied by Joffm on topic Dropdown box in array
Obviously you did not set "Checkbox Layout" to "Off" and "Text Inputs" to "On".



But why don't you use a question of type ranking for this?
You can set it that only five trees are selected.

Joffm

Volunteers are not paid.
Not because they are worthless, but because they are priceless
Last edit: 3 years 7 months ago by Joffm.
The topic has been locked.
  • Maribelcarol
  • Maribelcarol's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
3 years 7 months ago #205323 by Maribelcarol
Replied by Maribelcarol on topic Dropdown box in array
That's true! Thank you so much!
I prefere it like this for the design of the survey.
The topic has been locked.
  • Joffm
  • Joffm's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
3 years 7 months ago #205324 by Joffm
Replied by Joffm on topic Dropdown box in array
Don't forget to validate with "unique(self)"

Volunteers are not paid.
Not because they are worthless, but because they are priceless
The following user(s) said Thank You: Maribelcarol
The topic has been locked.

Lime-years ahead

Online-surveys for every purse and purpose