Old example survey on LS 3.25.7

More
4 weeks 1 day ago - 4 weeks 1 day ago #214716 by pepnoguera
 Hi everyone,For a couple of weeks now I've been trying to create a survey where I want my multiple choice questions to have a hidden value attached. I've search the forums and finally found this: forums.limesurvey.org/forum/can-i-do-thi...iple-choice-question

Here is the code I'm interested in:
$(document).ready(function() {
 
        // Identify the questions
        var qID = {QID};
        var thisQuestion = $('#question'+qID);
        var prevMultiChoice = $(thisQuestion).prevAll('.multiple-opt:eq(0)');
        
        // Hide this question
        $('#question'+qID).hide();
        
        // Find the initial score
        var totalScore = 0;
        $('input.checkbox:checked', prevMultiChoice).each(function(i) {
            var thisScore = $(this).attr('id').slice(-1);
            totalScore = totalScore + Number(thisScore);
        });
        // Store the score
        $('input[type="text"]', thisQuestion).val(totalScore);
 
        // Listener on the checkboxes
        $('input.checkbox', prevMultiChoice).change(function(event) {
            // Find the score
            totalScore = 0;
            $('input.checkbox:checked', prevMultiChoice).each(function(i) {
                var thisScore = $(this).attr('id').slice(-1);
                totalScore = totalScore + Number(thisScore);
            });
            // Store the score
            $('input[type="text"]', thisQuestion).val(totalScore);
        });
    });

I'm very new to LS and programming, but I'm pretty sure that this is what I've been looking for. Unfortunately, when I import the survey to LS 3.25.7 it doesn't work. What am I missing here?

Thanks!



 

File Attachment:

File Name: limesurvey...1968.lss
File Size:19 KB
Attachments:
Last edit: 4 weeks 1 day ago by pepnoguera.

Please Log in to join the conversation.

More
4 weeks 1 day ago #214719 by tpartner
I'm not surprised that it doesn't work after 7+ years.

Why the JavaScript? You can generate scores with ExpressionScript?

{score = sum(if(Q1_SQ001 =='Y', 1, 0), if(Q1_SQ002 =='Y', 3, 0), if(Q1_SQ003 =='Y', 1, 0), if(Q1_SQ004 =='Y', 2, 0))}

Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.

Please Log in to join the conversation.

More
4 weeks 1 day ago - 4 weeks 1 day ago #214720 by pepnoguera
I don't know. I found it clearer to use the SQ id to retrieve a value.

My objective is to create an enrollment survey. Each course has its modules with differents prices and you can choose which modules you want to enlist in.

Until now, what I've got is something similar to your proposal:
{if(!is_empty(Q1_SQ001), 1, 0)}

But I wanted something more readable as I have to change the values of this SQ constantly and I have at least 13 SQ in each survey. I found that having the SQ code next to the module's name was easier for me to understand.

Anyway, your solution works and at the end of the day that's what matters.

Thank you.
Last edit: 4 weeks 1 day ago by pepnoguera.

Please Log in to join the conversation.

More
4 weeks 20 hours ago #214723 by Joffm
Hi,

But I wanted something more readable as I have to change the values of this SQ constantly and I have at least 13 SQ in each survey

then I show you a really easy way to create these equations.

Assuming you have 5 subquestions and want to set the assessment values like
Subquestion 1: 1
Subquestion 2: 1
Subquestion 3: 2
Subquestion 4: 3
Subquestion 5: 3

First the "long" easy to understand version  (tpartner already showed):
You use the IF-statement:
{sum(
IF(Q1_SQ001=="Y",1,0),
IF(Q1_SQ002=="Y",1,0),
IF(Q1_SQ003=="Y",2,0),
IF(Q1_SQ004=="Y",3,0),
IF(Q1_SQ005=="Y",3,0)

)}

Here without the IF (knowing that a TRUE term is evaluated as "1")
​​​​​{sum(
intval(Q1_SQ001.NAOK=="Y") *1,
intval(Q1_SQ002.NAOK=="Y") *1,
intval(Q1_SQ003.NAOK=="Y") *2,
intval(Q1_SQ004.NAOK=="Y") *3,
intval(Q1_SQ005.NAOK=="Y") *3
)}


And this you can easily create in a spreadsheet with some concatination:
 

​​​​​​​Joffm


Volunteers are not paid.
Not because they are worthless, but because they are priceless
Attachments:
The following user(s) said Thank You: DenisChenu

Please Log in to join the conversation.

More
4 days 15 hours ago #215792 by pepnoguera
Thanks Joffm. That's perfect. I finally did what tpartner suggested, but I'll keep your version in mind for future reference.

Please Log in to join the conversation.

Start now!

Just create your account and start using Limesurvey today.

Register now