Check out the LimeSurvey source code on GitHub!
Welcome, Guest
Username: Password:

TOPIC: Saving totals to DB

Saving totals to DB 5 years 2 months ago #65479

  • sitiomatic
  • sitiomatic's Avatar
  • Offline
  • Fresh Lemon
  • Posts: 5
  • Karma: 0
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!
The administrator has disabled public write access.

Saving totals to DB 5 years 2 months ago #65481

  • TMSWhite
  • TMSWhite's Avatar
  • Offline
  • LimeSurvey Team
  • Posts: 758
  • Thank you received: 84
  • Karma: 37
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+
The administrator has disabled public write access.

Saving totals to DB 5 years 2 months ago #65483

  • Ben_V
  • Ben_V's Avatar
  • Offline
  • Platinum Lime
  • Posts: 1894
  • Thank you received: 469
  • Karma: 118
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
All LS releases => bit.ly/1VMuTDu | 2.06lts => bit.ly/1Qv44A1
Demo surveys => goo.gl/HuR6Xe (already included in /docs/demosurveys)
Last Edit: 5 years 2 months ago by Ben_V.
The administrator has disabled public write access.

Saving totals to DB 5 years 2 months ago #65518

  • sitiomatic
  • sitiomatic's Avatar
  • Offline
  • Fresh Lemon
  • Posts: 5
  • Karma: 0
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.
The administrator has disabled public write access.

Saving totals to DB 5 years 2 months ago #65520

  • holch
  • holch's Avatar
  • Offline
  • LimeSurvey Team
  • Posts: 5425
  • Thank you received: 807
  • Karma: 239
Did you follow the instructions on how to use JS in Limesurey? You need to switch off the XSS filter...
Have a look at the manual! It is a really valuable source for information. Here some helpful links:
Manual (EN) | Question Types | [url=https://manual.limesurvey.org/Workarounds[/url]

If you found this answer helpful and it saved you some time please consider a [url=https://donate.limesurvey.org[/url] to the...
The administrator has disabled public write access.

Saving totals to DB 5 years 2 months ago #65521

  • sitiomatic
  • sitiomatic's Avatar
  • Offline
  • Fresh Lemon
  • Posts: 5
  • Karma: 0
Thanks holch! Now everything it's working fine :)
The administrator has disabled public write access.

Saving totals to DB 5 years 2 months ago #65803

  • jg2011
  • jg2011's Avatar
  • Offline
  • Fresh Lemon
  • Posts: 3
  • Karma: 0
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.
The administrator has disabled public write access.

Saving totals to DB 5 years 2 months ago #65807

  • DenisChenu
  • DenisChenu's Avatar
  • Offline
  • Moderator Lime
  • Posts: 9572
  • Thank you received: 1374
  • Karma: 390
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 (use private message).
The administrator has disabled public write access.

Saving totals to DB 5 years 2 months ago #65817

  • Mazi
  • Mazi's Avatar
  • Offline
  • LimeSurvey Team
  • Posts: 6028
  • Thank you received: 373
  • Karma: 260
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'"
The administrator has disabled public write access.

Saving totals to DB 5 years 2 months ago #65890

  • jg2011
  • jg2011's Avatar
  • Offline
  • Fresh Lemon
  • Posts: 3
  • Karma: 0
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.
The administrator has disabled public write access.

Saving totals to DB 5 years 2 months ago #65897

  • jg2011
  • jg2011's Avatar
  • Offline
  • Fresh Lemon
  • Posts: 3
  • Karma: 0
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.
The administrator has disabled public write access.

Saving totals to DB 5 years 2 months ago #65955

  • Mazi
  • Mazi's Avatar
  • Offline
  • LimeSurvey Team
  • Posts: 6028
  • Thank you received: 373
  • Karma: 260
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 2 months ago by Mazi. Reason: SOURCE CODE CORRECTED
The administrator has disabled public write access.

Saving totals to DB 5 years 2 months ago #65957

  • TMSWhite
  • TMSWhite's Avatar
  • Offline
  • LimeSurvey Team
  • Posts: 758
  • Thank you received: 84
  • Karma: 37
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.
The administrator has disabled public write access.

Saving totals to DB 5 years 2 months ago #65967

  • Ben_V
  • Ben_V's Avatar
  • Offline
  • Platinum Lime
  • Posts: 1894
  • Thank you received: 469
  • Karma: 118
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
All LS releases => bit.ly/1VMuTDu | 2.06lts => bit.ly/1Qv44A1
Demo surveys => goo.gl/HuR6Xe (already included in /docs/demosurveys)
Last Edit: 5 years 2 months ago by Ben_V.
The administrator has disabled public write access.
Time to create page: 0.579 seconds
Imprint                   Privacy policy         General Terms & Conditions         Revocation information and revocation form