Welcome to the LimeSurvey Community Forum

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

Hide Tip

  • psychgit
  • psychgit's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
2 years 9 months ago #230654 by psychgit
Hide Tip was created by psychgit
Please help us help you and fill where relevant:
Your LimeSurvey version: Version 3.24.2
Own server or LimeSurvey hosting: LimeSurvey Hosting
Survey theme/template:
==================
Hello,

I have very little experience with javascript but I am trying to hide the "Only numbers may be entered in these fields." tip. I have turned the tip off yet it still appears. Please help!  Here my question source script:
<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">Not at all</option>\
<option value="2">A little </option>\
<option value="3">Somewhat </option>\
<option value="4">Quite a lot </option>\
<option value="5">Very much </option>\
<option value="6">Not applicable </option>\
</select>');  
 
// Listeners
$('.inserted-select', thisQuestion).on('change', function(i) {
if($(this).val() != '') {
$(this).closest('.answer-item').find('input:text').val($.trim($('option:selected', this).text())).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 inputText = $.trim($(this).val());
var selectval = $('select.inserted-select option', thisCell).filter(function () { return $(this).html() == inputText; }).val();
$('select.inserted-select', thisCell).val(selectval);
});
 
// Clean-up styles
$('select.inserted-select', thisQuestion).css({
'max-width': '100%'
});
$('input:text', thisQuestion).css({
'position': 'absolute',
'left': '-9999em'
});
});
</script>

 

Please Log in to join the conversation.

  • Joffm
  • Joffm's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
2 years 9 months ago #230657 by Joffm
Replied by Joffm on topic Hide Tip
Hi,
what type of question are you using?

I assume "array(numbers)"?
This is the wrong question type for the wrong script.

This script is used to insert drop-downs into the cells of an "array(text)".
The insertion of the drop-downs work in an array(numbers).
But obviously you will always get the error message, because you do not enter numbers
Did you ever activate this survey to see what is stored?

So the first is:
Use an array(text).

The second:
Use the correct version of the script.

This version of the script stores the text of the selections.
If you activate the survey and enter some data you will see this in the answer table
 
 
But I think you want to store the values. 
 
  
To store them you have to use this 
(more or less only the part "Returning to page" changed, and some other smaller issues)
Code:
<script type="text/javascript" charset="utf-8">
  $(document).on('ready pjax:scriptcomplete',function(){
    var thisQuestion = $('#question{QID}');
 
    // Insert selects
    $('.answer-item', thisQuestion).addClass('with-select').append('<select class="inserted-select form-control list-question-select">\
      <option value="">Please choose...</option>\
      <option value="1">Not at all</option>\
      <option value="2">A little </option>\
      <option value="3">Somewhat </option>\
      <option value="4">Quite a lot </option>\
      <option value="5">Very much </option>\
      <option value="6">Not applicable </option>\
    </select>');
 
    // Listeners
    $('.inserted-select', thisQuestion).on('change', function(i) {
      if($(this).val() != '') {
        $(this).closest('.answer-item').find('input:text').val($('option:selected', this).val()).trigger('change');
      }
      else {
        $(this).closest('.answer-item').find('input:text').val('').trigger('change');
      }
    });
 
  // Returning to page
    $('.with-select input:text', thisQuestion).each(function(i) {
      var thisCell = $(this).closest('.answer-item');
      var inputText = $.trim($(this).val());
      $('select.inserted-select', thisCell).val(inputText);
    });
 
    // Clean-up styles
    $('select.inserted-select', thisQuestion).css({
      'max-width': '100%'
    });
    $('.with-select input:text', thisQuestion).css({
      'position': 'absolute',
      'left': '-9999em'
    });
  });
</script>

 

Joffm

Volunteers are not paid.
Not because they are worthless, but because they are priceless

Please Log in to join the conversation.

  • psychgit
  • psychgit's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
2 years 9 months ago #230700 by psychgit
Replied by psychgit on topic Hide Tip
Thank you so much!!!

Please Log in to join the conversation.

Moderators: holchtpartner

Lime-years ahead

Online-surveys for every purse and purpose