- Posts: 5
- Thank you received: 0
Welcome to the LimeSurvey Community Forum
Ask the community, share ideas, and connect with other LimeSurvey users!
Old example survey on LS 3.25.7
- pepnoguera
- Topic Author
- Offline
- New Member
Less
More
3 years 2 weeks ago - 3 years 2 weeks ago #214716
by pepnoguera
Old example survey on LS 3.25.7 was created 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:[url]
forums.limesurvey.org/forum/can-i-do-thi...iple-choice-question
[/url]
Here is the code I'm interested in:
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!
Here is the code I'm interested in:
Code:
$(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!
Last edit: 3 years 2 weeks ago by pepnoguera.
The topic has been locked.
- tpartner
- Offline
- LimeSurvey Community Team
Less
More
- Posts: 10109
- Thank you received: 3595
3 years 2 weeks ago #214719
by tpartner
Cheers,
Tony Partner
Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
Replied by tpartner on topic Old example survey on LS 3.25.7
I'm not surprised that it doesn't work after 7+ years.
Why the JavaScript? You can generate scores with ExpressionScript?
Why the JavaScript? You can generate scores with ExpressionScript?
Code:
{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.
The topic has been locked.
- pepnoguera
- Topic Author
- Offline
- New Member
Less
More
- Posts: 5
- Thank you received: 0
3 years 2 weeks ago - 3 years 2 weeks ago #214720
by pepnoguera
Replied by pepnoguera on topic Old example survey on LS 3.25.7
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:
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.
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:
Code:
{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: 3 years 2 weeks ago by pepnoguera.
The topic has been locked.
- Joffm
- Offline
- LimeSurvey Community Team
Less
More
- Posts: 12940
- Thank you received: 3979
3 years 2 weeks ago #214723
by Joffm
Volunteers are not paid.
Not because they are worthless, but because they are priceless
Replied by Joffm on topic Old example survey on LS 3.25.7
Hi,
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
then I show you a really easy way to create these equations.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
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
The following user(s) said Thank You: DenisChenu
The topic has been locked.
- pepnoguera
- Topic Author
- Offline
- New Member
Less
More
- Posts: 5
- Thank you received: 0
2 years 11 months ago #215792
by pepnoguera
Replied by pepnoguera on topic Old example survey on LS 3.25.7
Thanks Joffm. That's perfect. I finally did what tpartner suggested, but I'll keep your version in mind for future reference.
The topic has been locked.