- Posts: 33
- Thank you received: 1
Welcome to the LimeSurvey Community Forum
Ask the community, share ideas, and connect with other LimeSurvey users!
Store that page has been shown in database.
- flink
- Topic Author
- Offline
- Junior Member
Less
More
10 years 4 months ago #102237
by flink
Store that page has been shown in database. was created by flink
Hello everybody,
I'm trying to do the following: people that have given unusual answers are shown a message on the next page that tells them to recheck their answers. They now can either proceed to the next question page or go back and change their answers.
I use an equation to evaluate the answers and set a flag. This flag is used as the relevance condition for the subsequent warning page (i made the warning a question group). What I want to do now is store in the database that the warning page has been shown.
For example, somebody has given unusual answers, gets the warning message on the next page, turns back to change his answers and then proceeds. If the answers are not unusual anymore on the 2nd time, the warning page will be skipped. I want to store the information in the database that the participant was initially shown the warning message. I tried to set a flag "shown" right after the warning message, but when the group is skipped, the variable loses its value.
Does anybody have an idea how to solve this?
Thanks in advance!
I'm trying to do the following: people that have given unusual answers are shown a message on the next page that tells them to recheck their answers. They now can either proceed to the next question page or go back and change their answers.
I use an equation to evaluate the answers and set a flag. This flag is used as the relevance condition for the subsequent warning page (i made the warning a question group). What I want to do now is store in the database that the warning page has been shown.
For example, somebody has given unusual answers, gets the warning message on the next page, turns back to change his answers and then proceeds. If the answers are not unusual anymore on the 2nd time, the warning page will be skipped. I want to store the information in the database that the participant was initially shown the warning message. I tried to set a flag "shown" right after the warning message, but when the group is skipped, the variable loses its value.
Does anybody have an idea how to solve this?
Thanks in advance!
The topic has been locked.
- tpartner
- Offline
- LimeSurvey Community Team
Less
More
- Posts: 10099
- Thank you received: 3589
10 years 4 months ago #102245
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 Store that page has been shown in database.
You should also be able to load a hidden
Equation type question
using your "flag" equation.
Cheers,
Tony Partner
Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
The topic has been locked.
- flink
- Topic Author
- Offline
- Junior Member
Less
More
- Posts: 33
- Thank you received: 1
10 years 4 months ago #102247
by flink
I tried using hidden equations, but it does not work. Here is what happens:
1) Page 1 (questions) --> user gives unusual answers --> showwarning = 1
2) if showwarning == 1 --> Page 2 (warning) --> flag = 1
3) user goes back
4) Page 1 (questions) --> user gives normal answers --> showwarning = 0
5) Page 2 is skipped and the questionnaire continues
In this case, the flag variable does not keep its value 1 so that I cannot know whether the warning has been shown or not.
Replied by flink on topic Store that page has been shown in database.
tpartner wrote: You should also be able to load a hidden Equation type question using your "flag" equation.
I tried using hidden equations, but it does not work. Here is what happens:
1) Page 1 (questions) --> user gives unusual answers --> showwarning = 1
2) if showwarning == 1 --> Page 2 (warning) --> flag = 1
3) user goes back
4) Page 1 (questions) --> user gives normal answers --> showwarning = 0
5) Page 2 is skipped and the questionnaire continues
In this case, the flag variable does not keep its value 1 so that I cannot know whether the warning has been shown or not.
The topic has been locked.
- tpartner
- Offline
- LimeSurvey Community Team
Less
More
- Posts: 10099
- Thank you received: 3589
10 years 4 months ago - 10 years 4 months ago #102248
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 Store that page has been shown in database.
You can add an IF clause to the equation to detect whether the hidden question has been previously populated. If so, it stays the same.
So, if the question code for the hidden equation question is "flag", something like this...
So, if the question code for the hidden equation question is "flag", something like this...
Code:
if(flag >= 1, flag, [your equation])
Cheers,
Tony Partner
Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
Last edit: 10 years 4 months ago by tpartner.
The topic has been locked.
- flink
- Topic Author
- Offline
- Junior Member
Less
More
- Posts: 33
- Thank you received: 1
10 years 4 months ago #102249
by flink
Replied by flink on topic Store that page has been shown in database.
This is what I wanted to do, but I cannot access the flag variable on page 1 because it is only declared on page 2. I get the error message: "this variable is not declared until a later page."
I tried setting the flag to 0 on a prior page but that doesn't help either.
I tried setting the flag to 0 on a prior page but that doesn't help either.
The topic has been locked.
- tpartner
- Offline
- LimeSurvey Community Team
Less
More
- Posts: 10099
- Thank you received: 3589
10 years 4 months ago - 10 years 4 months ago #102253
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 Store that page has been shown in database.
Well, instead of using a "warning" group, you could use JavaScript on page 1 to pop up a confirm message and populate a hidden question.
For example this script placed in the source of "qHidden" in the attached sample survey will:
- Hide its parent question
- Interrupt the submit function
- If Q2 is found to be greater than Q1 a confirm box is popped up and the hidden question is given a value of "1"
- If "Cancel" is clicked, the submit function is aborted allowing the respondent to change their answers
For example this script placed in the source of "qHidden" in the attached sample survey will:
- Hide its parent question
- Interrupt the submit function
- If Q2 is found to be greater than Q1 a confirm box is popped up and the hidden question is given a value of "1"
- If "Cancel" is clicked, the submit function is aborted allowing the respondent to change their answers
Code:
<script type="text/javascript" charset="utf-8"> $(document).ready(function(){ // Identify some stuff var qHiddenID = {QID}; var qHidden = $('#question'+qHiddenID); var q1 = $('div.numeric:eq(0)'); // First numeric on the page var q2 = $('div.numeric:eq(1)'); // Second numeric on the page // Hide this question $(qHidden).hide(); // Interrupt the Next/Submit function and validate each column $('form#limesurvey').submit(function(){ // Override the built-in "disable navigation buttons" feature $('#moveprevbtn, #movenextbtn, #movesubmitbtn').attr('disabled', ''); // Q2 value is greater than Q1 value if ($('input.text', q2).val() > $('input.text', q1).val()) { // Populate the hidden question $('input.text', qHidden).val('1'); // Pop up a confirm message if(confirm('Are you sure of your answer?')) { return true; } else { return false; } } }); }); </script>
Cheers,
Tony Partner
Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
Attachments:
Last edit: 10 years 4 months ago by tpartner.
The following user(s) said Thank You: flink
The topic has been locked.
- flink
- Topic Author
- Offline
- Junior Member
Less
More
- Posts: 33
- Thank you received: 1
10 years 4 months ago #102256
by flink
Replied by flink on topic Store that page has been shown in database.
Thank you very much, it works!
One last question: If I try to modify the code and save it, the code gets scrambled (see picture). This also happens when I don't change anything at all but just save it via the editor. How can I save the modified script?
btw: I am using Version 1.92+ Build 120919
One last question: If I try to modify the code and save it, the code gets scrambled (see picture). This also happens when I don't change anything at all but just save it via the editor. How can I save the modified script?
btw: I am using Version 1.92+ Build 120919
Attachments:
The topic has been locked.
- tpartner
- Offline
- LimeSurvey Community Team
Less
More
- Posts: 10099
- Thank you received: 3589
10 years 4 months ago #102257
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 Store that page has been shown in database.
Cheers,
Tony Partner
Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
Attachments:
The following user(s) said Thank You: flink
The topic has been locked.
- flink
- Topic Author
- Offline
- Junior Member
Less
More
- Posts: 33
- Thank you received: 1
10 years 4 months ago #102258
by flink
Replied by flink on topic Store that page has been shown in database.
Everything works now. Again, thank you very much!
The topic has been locked.