Check out the LimeSurvey source code on GitHub!

Saving totals to DB

More
5 years 5 months ago #65479 by sitiomatic
Hello everyone.
I have a poll with 5 sections of 20 questions.
It is a contest, and each question has a 1 point value. Wins the contest the participant who gets more points.
When the survey is complete it shows the result to the participant.
My problem is that it is not recorded anywhere and when I export the results I have not the total of each participant.
Since the only information that interests me is the total of each participant, how can get this saved to export it?
Thanks for the help!

Please Log in to join the conversation.

More
5 years 5 months ago #65481 by TMSWhite
LimeSurvey 1.92 solves this. There is an Equation question type that can compute and store totals. See details here .

I'm afraid you'll have to ask someone else for suggestions about how to do this with LimeSurvey 1.91+

Please Log in to join the conversation.

More
5 years 5 months ago - 5 years 5 months ago #65483 by Ben_V
Hi,
1) Set your survey "group by group" or "question by question"
2) Create a (hidden) numerical input question type
3) in the source of the question put this js code snippet adapting the SGQA Identifier
123*= Survey ID
456*= Question Group ID
789*= Question ID
<script> 
jQuery(document).ready(function() {
	document.getElementById('answer123X456X789').value = "{assessment_CURRENT_TOTAL}";
document.getElementById('display789').style.display= "none";
document.getElementById('answer123X456X789').style.display= "none";
});
</script>
Check it
* just for the example...could be more digits


Benoît

EM Variables => bit.ly/1TKQyNu | EM Roadmap => bit.ly/1UTrOB4
Last Releases => 2.6x.x goo.gl/ztWfIV | 2.06/2.6.x => bit.ly/1Qv44A1
Demo Surveys => goo.gl/HuR6Xe (already included in /docs/demosurveys)
Attachments:
Last Edit: 5 years 5 months ago by Ben_V.

Please Log in to join the conversation.

More
5 years 5 months ago #65518 by sitiomatic
The script is working great. Thanks!
I have a problem adding the text <script> to the question. When I save the question, <script> is replaced with <sc<x>ript> and it doesn't work.
I added the text to the database using phpmyadmin.
Html editor is off.

Please Log in to join the conversation.

More
5 years 5 months ago #65520 by holch
Did you follow the instructions on how to use JS in Limesurey? You need to switch off the XSS filter...

I'm not a LimeSurvey GmbH member. I answer at the LimeSurvey forum in my spare time. No support via private message.
Some helpful links: Manual (EN) | Question Types | Workarounds

Please Log in to join the conversation.

More
5 years 5 months ago #65521 by sitiomatic
Thanks holch! Now everything it's working fine :)

Please Log in to join the conversation.

More
5 years 5 months ago #65803 by jg2011
I am on 1.90 build 9343.
I have tried the exact steps described by Ben above. I have javascript seton via the XSS switch.
The assessment total is displayed correctly at the end of the survey.

<script>
jQuery(document).ready(function() {
document.getElementById('answer73863X92X946').value = "{assessment_CURRENT_TOTAL}";
document.getElementById('display73863').style.display= "none";
document.getElementById('answer73863X92X946').style.display= "none";
});
</script>

But the assessment_CURRENT_TOTAL is not stored in the database by the javascript above.

What else is missing in the steps above? Note: I have only one question group, and the hidden question is the last question (946) in that group (92).

Do I need to thave a line for GROUP in the ASSESSMENTS Area of the survey? I only have one line now - for the TOTAL. And THAT is working.

Your help is appreciated.

Please Log in to join the conversation.

More
5 years 5 months ago #65807 by DenisChenu
Can you try:
<script>
jQuery(document).ready(function() {
('#question946 input.text').val({assessment_CURRENT_TOTAL});
// ('#question946').hide(); // remove the // after testing to hide the question
});
</script>

Assistance on LimeSurvey forum and LimeSurvey core development are on my free time.
I'm not a LimeSurvey GmbH member, professional service on demand (or search sondages pro).

Please Log in to join the conversation.

More
5 years 5 months ago #65817 by Mazi

jg2011 wrote: What else is missing in the steps above? Note: I have only one question group, and the hidden question is the last question (946) in that group (92).

If I remember correctly the function to calculate the current total assessment value reads out the data from the database. Data is saved to the database each time you click next so you should try to switch your survey to question-by-question mode or add a second group holding the numrical question.


Best regards/Beste Grüße,
Dr. Marcel Minke
(Limesurvey Head of Support)
Need Help? We offer professional Limesurvey support
Contact: marcel.minke(at)survey-consulting.com'"

Please Log in to join the conversation.

More
5 years 5 months ago #65890 by jg2011
Thank you both for the prompt assistance.
Shnoulee: Is there something missing here?
('#question946 input.text').val({assessment_CURRENT_TOTAL});
There is no $ at the beginning and that space between the 6 and the i...how does that work? Please note, I am NOT a javascript expert.

Mazi: The Next button does cause assessment_CURRENT_TOTAL to be calculated. I was able to see this when I added a numeric question at the end of the question group, added the exact code as shown, and made it visible rather than hidden. However, IF the question is then hidden, it doesn't calculate!!! I don't want the user to see the interim assessment score. Since all answers are mandatory, if they would not complete a response, and then lick Next, an error message would be displayed - along with the raw assessment score.

One option is to make the survey question by question.

But I do not see why hiding a question should cause the code not to execute.

Ideas and thoughts welcome.

Please Log in to join the conversation.

More
5 years 5 months ago #65897 by jg2011
I just found this post bugs.limesurvey.org/view.php?id=5375
Scripts do not run for hidden questions. c_schmitz states "this is intended behaviour".

So any solution using a hidden question with javascript to save assessment totals to the database cannot work.

Please Log in to join the conversation.

More
5 years 5 months ago - 5 years 5 months ago #65955 by Mazi
jg2011, the bug report states "If you hide a question (by setting "Always hide this question" to Yes), then any script embedded in the question text is not executed."

The reason is that in that case no HTML is generated at all so you can't fill the question and nothing will be saved.

The solution is to hide the question by using Javascript at the question text. To hide a question using Javascript you first have to disable the internal <a href=' docs.limesurvey.org/tiki-index.php?page=...al+settings#Security '>XSS</a> filter at the admin section (global settings -> security -> "Filter HTML for <a href=' docs.limesurvey.org/tiki-index.php?page=...al+settings#Security '>XSS</a> = 'no'").
Then you ahve to edit the according question. Edit the question text in source code mode and add this snippet at the end of the text:
 
<script>
   $(document).ready(function() 
   {
      $('#question4444').hide();
   });
</script>
 
 
You have to replace the question ID ("4444") with the ID of the current question .


Best regards/Beste Grüße,
Dr. Marcel Minke
(Limesurvey Head of Support)
Need Help? We offer professional Limesurvey support
Contact: marcel.minke(at)survey-consulting.com'"
Last Edit: 5 years 5 months ago by Mazi. Reason: SOURCE CODE CORRECTED

Please Log in to join the conversation.

More
5 years 5 months ago #65957 by TMSWhite
FYI, Expression Manager also helps address this 'hidden' behavior in LimeSurvey 1.92. Relevance (whether a question should be processed) and Visibility are now separated. That way, you can have an Equation question that is relevant, but hidden. Anything that is relevant is saved to the database, even if it is hidden via the "Always hide this question" option. This is the strategy you can take for your hidden assessment scores in the future.

Please Log in to join the conversation.

More
5 years 5 months ago - 5 years 5 months ago #65967 by Ben_V

One option is to make the survey question by question

Yes... or probably better group by group with:
Group#1: All your survey questions
Group#2: your hiddden (or not ) question for asssessments stuff
Now you can force the submit action for your Group#2's question adding this to its answer source:
<script>
jQuery(document).ready(function($) {
document.limesurvey.submit();});
</script>
BenoÎt

Benoît

EM Variables => bit.ly/1TKQyNu | EM Roadmap => bit.ly/1UTrOB4
Last Releases => 2.6x.x goo.gl/ztWfIV | 2.06/2.6.x => bit.ly/1Qv44A1
Demo Surveys => goo.gl/HuR6Xe (already included in /docs/demosurveys)
Last Edit: 5 years 5 months ago by Ben_V.

Please Log in to join the conversation.

Imprint                   Privacy policy         General Terms & Conditions         Revocation information and revocation form