Welcome, Guest
Username: Password: Remember me

TOPIC: Store that page has been shown in database.

Store that page has been shown in database. 9 months 3 weeks ago #102237

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

Store that page has been shown in database. 9 months 3 weeks ago #102245

  • tpartner
  • tpartner's Avatar
  • OFFLINE
  • LimeSurvey Team
  • Posts: 4206
  • Thank you received: 790
  • Karma: 360
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.

LimeSurvey is open-source and run entirely by volunteers so please consider donating to support the project.
The administrator has disabled public write access.

Store that page has been shown in database. 9 months 3 weeks ago #102247

  • flink
  • flink's Avatar
  • OFFLINE
  • Fresh Lemon
  • Posts: 19
  • Karma: 0
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 administrator has disabled public write access.

Store that page has been shown in database. 9 months 3 weeks ago #102248

  • tpartner
  • tpartner's Avatar
  • OFFLINE
  • LimeSurvey Team
  • Posts: 4206
  • Thank you received: 790
  • Karma: 360
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...

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.

LimeSurvey is open-source and run entirely by volunteers so please consider donating to support the project.
Last Edit: 9 months 3 weeks ago by tpartner.
The administrator has disabled public write access.

Store that page has been shown in database. 9 months 3 weeks ago #102249

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

Store that page has been shown in database. 9 months 3 weeks ago #102253

  • tpartner
  • tpartner's Avatar
  • OFFLINE
  • LimeSurvey Team
  • Posts: 4206
  • Thank you received: 790
  • Karma: 360
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

<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>


File Attachment:

File Name: limesurvey_survey_913978_2013-12-04.lss
File Size: 15 KB
Cheers,
Tony Partner

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

LimeSurvey is open-source and run entirely by volunteers so please consider donating to support the project.
Last Edit: 9 months 3 weeks ago by tpartner.
The administrator has disabled public write access.
The following user(s) said Thank You: flink

Store that page has been shown in database. 9 months 3 weeks ago #102256

  • flink
  • flink's Avatar
  • OFFLINE
  • Fresh Lemon
  • Posts: 19
  • Karma: 0
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
Attachments:
The administrator has disabled public write access.

Store that page has been shown in database. 9 months 3 weeks ago #102257

  • tpartner
  • tpartner's Avatar
  • OFFLINE
  • LimeSurvey Team
  • Posts: 4206
  • Thank you received: 790
  • Karma: 360
You need to disable the XSS filter - manual.limesurvey.org/Global_settings#Security

Capture_2013-12-04.PNG
Cheers,
Tony Partner

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

LimeSurvey is open-source and run entirely by volunteers so please consider donating to support the project.
The administrator has disabled public write access.
The following user(s) said Thank You: flink

Store that page has been shown in database. 9 months 3 weeks ago #102258

  • flink
  • flink's Avatar
  • OFFLINE
  • Fresh Lemon
  • Posts: 19
  • Karma: 0
Everything works now. Again, thank you very much!
The administrator has disabled public write access.
Moderators: ITEd
Time to create page: 0.184 seconds
Donation Image