Welcome to the LimeSurvey Community Forum

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

Adding "Other:" option to array

  • stemar68
  • stemar68's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
2 days 3 hours ago #269568 by stemar68
Adding "Other:" option to array was created by stemar68
Please help us help you and fill where relevant:
Your LimeSurvey version: 6.11.0+250303
Own server or LimeSurvey hosting: own server
Survey theme/template: Fruity
==================
Hello everybody,
I need to add at the end of the subquestions in an array the "Other:" option, so that the user can write in their own subquestion and then select one of the answer options.
I try to use the solution of  tpartner  #226851for limesurvey 5, but seems not work.
Any suggestions are welcome.
Thank you very much.

Please Log in to join the conversation.

  • Joffm
  • Joffm's Avatar
  • Away
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
2 days 13 minutes ago - 1 day 22 hours ago #269573 by Joffm
Replied by Joffm on topic Adding "Other:" option to array
Hi,
1. The scripts work at least since version 3.x. without modification.

But you did not mention which type of array you are using.
Is this script the right one for your array? You have to distinguish between "array" and "array(text) / array(number)".
Unfortunately you did not give a link to this script. And the forum doesn't give a result when you search for something like "226851".

So please tell us which type of array you use and which script you want to use.
The best to do this is to provide a lss export of these relevant questions.

But here a working script for question type "array"
Code:
<script type="text/javascript" charset="utf-8">    
    $(document).ready(function() {
 
        // Identify the questions
        var thisQuestion = $('#question'+{QID}+'');
        var nextQuestion1 = $(thisQuestion).nextAll('.text-short:eq(0)');
        var nextQuestions = $(nextQuestion1);
        var nextLength = nextQuestions.length;
        var sqLength = ('tr.answers-list', thisQuestion).length;
 
        // Hide the short-text questions
        $(nextQuestions).hide();
 
        // Move the hidden text inputs into the array
        for (i = 0; i < nextLength; i++) {
            var workingIndex = (sqLength - 1) - (nextLength - i);
            var nextQ = nextQuestions[i];
            $('th.answertext:eq('+workingIndex+')', thisQuestion).append($('input[type="text"]', nextQ)).closest('tr').addClass('otherRow');
        }    
 
        // Some styling...
        $('input[type="text"]', thisQuestion).css({
            'width': '100%'
        });        
 
        // Handle the "Other" radios
        $('input[type="text"]', thisQuestion).on('keyup change',function(event){
            event.stopPropagation();
 
            var thisRow = $(this).closest('tr.answers-list');            
            if($.trim($(this).val()) == '') {
                $('input:radio[value!=""]', thisRow).prop('checked',false);
                $('input:radio[value=""]', thisRow).click();
            }
            else {
                $('input:radio[value=""]', thisRow).prop('checked',false);
            }
        });    
 
        // Handle the "Other" text inputs
        $('.otherRow input.radio', thisQuestion).on('click',function(event){
            var thisRow = $(this).closest('tr.answers-list');
            if($(this).attr('value') == '') {
                $('input[type="text"]', thisRow).val('');
            }
        });
 
        // Validate the "Other" text inputs on submit
        if($('#ls-button-submit').attr('data-inserted-other') != 'true') { // We're only doing this once on this page
            $('#ls-button-submit').attr('data-inserted-other', 'true').on('click.insertedOther', function (event) {
 
                var otherError = 0;
 
                $('.array-flexible-row .otherRow').each(function(i) {
 
                    if(($('input:radio[value!=""]:checked', this).length > 0 &amp;&amp; $('input[type="text"]', this).val() == '') || ($('input:radio[value!=""]:checked', this).length == 0 &amp;&amp; $('input[type="text"]', this).val() != '')) {
                        otherError = 1;
                    }
                });
 
                if(otherError == 1) {
                    alert('Überprüfen Sie die Angaben in den "Sonstigen"-Zeilen!');
                    return false;
                }
            });
        }
    });
</script>[/i]




2. Now my opinion about these "Others" in an array question.
Frankly said: It is useless.
Why?
  • The items of an array are tested in a pretest for reliability and validity, I hope.
    New items are not.
    And in many cases you will get "Others" that are already covered by the precoded items.
  • These "Others" will be "running lice", meaning the frequency of each will be very low. So the bases are really small and you are not able to calculate any statistical measure nor statistical tests (usually you start here with t-tests or ANOVA)
  • If there is a question like "How do you rate ..." and a scale like "excellent - very poor", nobody will enter an "Other" and rate it "very poor". Usualy you will get only new items people like.. This way you get an enormous bias -  if you calculate statistical tests.


We always tried to convince our customers to ask this question differently, namely simply in an open-ended additional question "Is there anything else that is important to you /  that you prefer / that you ...".

Joffm

Volunteers are not paid.
Not because they are worthless, but because they are priceless
Last edit: 1 day 22 hours ago by Joffm.

Please Log in to join the conversation.

  • stemar68
  • stemar68's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
1 day 5 hours ago #269592 by stemar68
Replied by stemar68 on topic Adding "Other:" option to array
Hi Joffm,
first of all thank you. The script I found is at this link  forums.limesurvey.org/forum/can-i-do-thi...ther-option-to-array
I use the array type F
I export and attach the question with your code, but I'm still having problems with execution.
I understand the point of view about your second point.

Please Log in to join the conversation.

  • Joffm
  • Joffm's Avatar
  • Away
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
1 day 3 hours ago #269594 by Joffm
Replied by Joffm on topic Adding "Other:" option to array
Please, neither *.lsq nor *.lsg exports, only *.lss

Reason(s): lsq and lsg exports are language sensitive. You can only import into a survey with the same base language.
So we have to guess the base language of the export, create a survey, create a group.
Furthermore the survey wide settings are missing which may be important, too.

So always the best:
Copy the survey, remove everything not related to your problem, export the rest as lss

Joffm
 

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

Please Log in to join the conversation.

  • stemar68
  • stemar68's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
1 day 2 hours ago #269596 by stemar68
Replied by stemar68 on topic Adding "Other:" option to array
Question to test

Please Log in to join the conversation.

  • Joffm
  • Joffm's Avatar
  • Away
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
22 hours 10 minutes ago - 22 hours 8 minutes ago #269605 by Joffm
Replied by Joffm on topic Adding "Other:" option to array
Hi,
You did not take this first sentence into account
[url] forums.limesurvey.org/forum/can-i-do-thi...tion-to-array#226851 [/url]

Add a short-text question in the same group directly after the array question and then add this scripot to the source of the array question:

You need a question to store the text that is entered in this "Other" field.
Then both scripts work.
You see that the original is much shorter.
Well, this does not check that there is a mention if a button was clicked and viceversa.

Next: Of course this question can't be mandatory. If set to "mandatory" rhe respondent aleays has to fill the last ("Other") row.
You should check by question validation that all fixed items are answered.

And you have to translate the message in the alert.
 

File Attachment:

File Name: limesurvey...36_J.lss
File Size:39 KB

Joffm


 

Volunteers are not paid.
Not because they are worthless, but because they are priceless
Last edit: 22 hours 8 minutes ago by Joffm.

Please Log in to join the conversation.

  • stemar68
  • stemar68's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
4 hours 51 minutes ago #269616 by stemar68
Replied by stemar68 on topic Adding "Other:" option to array
Hi,
I am so sorry, I think I have done all point you suggest me:
  • I add short text question just after the array
  • I put the script in the source array question
  • I remove the mandatory option in the array
  • also translate the alert
but still not running.
When i click preview survey I saw the array question and then the short text.
 Where I am going wrong...

Please Log in to join the conversation.

  • Joffm
  • Joffm's Avatar
  • Away
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
2 hours 35 minutes ago #269620 by Joffm
Replied by Joffm on topic Adding "Other:" option to array
Hi,
1. Your survey seemed to be in mode "question by question"
It has to be displayed "group by group" ( you want to display two questions, but visually merged)

Therefore we always recommend to display "group by group", but with only one question per group.
This is the miost flexible way.
You can use scripts to merge questions, you can display two questions on one page.
But the general look & feel is "question by question"

2. Your editor seemed to have changed the "&" to "&amp;"
Code:
                $('.array-flexible-row .otherRow').each(function(i) {
 
                    if(($('input:radio[value!=""]:checked', this).length > 0 &amp;amp;&amp;amp; $('input[type="text"]', this).val() == '') || ($('input:radio[value!=""]:checked', this).length == 0 &amp;amp;&amp;amp; $('input[type="text"]', this).val() != '')) {
                        otherError = 1;
                    }
                });
 
Take care of this.

3. alert('Controllare l'opzione altro!'); 
This will break the script.
You have rhe second (closing) quote after "lare l".

Either you have to use alternating quotes
alert("Controllare l'opzione altro!"); 
Or you use the escape-character
alert('Controllare l\'opzione altro!'); 
Read this
[url] www.w3schools.com/js/js_strings.asp [/url]

 

 

File Attachment:

File Name: limesurvey...8736.lss
File Size:46 KB

Joffm
 

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

Please Log in to join the conversation.

  • stemar68
  • stemar68's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
1 hour 44 minutes ago #269626 by stemar68
Replied by stemar68 on topic Adding "Other:" option to array
Great!!!
It works!!!
Thank you very much Joffm!!!

Please Log in to join the conversation.

Moderators: tpartnerholch

Lime-years ahead

Online-surveys for every purse and purpose