Save entered responses to database using jquery

More
2 months 3 weeks ago #158594 by eirikat
eirikat created the topic: Save entered responses to database using jquery
I have a one-page survey, and am experiencing that answers are not stored, unless the "Submit"-button at the bottom is clicked (which, surely, is the expected survey behavior). However, is there a way to ensure that answers are collected, even when the respondent refreshes the browser to start over - instead of clicking the button? Could one collect answers in real time, for example?

Alternatively, how could I create a second button at the top of the survey, which would also serve as a way to complete it and store the entered data? It is not paramount that all fields are filled every time, and the same user will respond to the survey many times, so my main concern is to remove any unnecessary hurdles. I have made an attempt at this, using jQuery:
		if (window.print) {
			$( "#customsubmit" ).button({
				label: "Submit"
			});
			$( "#customsubmit" ).click( function() {
				document.limesurvey.submit();
			});
		}

This successfully completes the survey when I click on "Submit" but, alas, does not store any data. Even though the document.limesurvey.submit(); seemed tailored for the purpose... Is there another function I could use instead? Or do I need to make adjustments to my code? My LimeSurvey version: 2.05+

Please Log in to join the conversation.

More
2 months 3 weeks ago #158609 by tpartner
tpartner replied the topic: Save entered responses to database using jquery
Try this (untested):

			$( "#customsubmit" ).click( function() {
				$('#movenextbtn, #movesubmitbtn').trigger('click');
			});

Cheers,
Tony Partner
Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
The following user(s) said Thank You: eirikat

Please Log in to join the conversation.

More
2 months 3 weeks ago #158611 by eirikat
eirikat replied the topic: Save entered responses to database using jquery
Thank you, Tony! With this, the data are now stored when I click my button.

Do you have any input on the other part of my question? I have discovered the window.onbeforeunload and window. onload handles, which should fire when the user refreshes the page, though I haven't been able to make these work yet.

Please Log in to join the conversation.

More
2 months 3 weeks ago #158670 by tpartner
tpartner replied the topic: Save entered responses to database using jquery
The only clean way I see to do this is to have an interval timer periodically make an AJAX call to a remote PHP script that updates the database directly.

Unfortunately, I not in a position to offer any substantial code for a week or more.

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

Please Log in to join the conversation.

More
2 months 3 weeks ago #158688 by eirikat
eirikat replied the topic: Save entered responses to database using jquery
Ok, thanks for the input! If, indeed, you have time to look at this in more detail, that would be greatly appreciated. I will be patient :)

Please Log in to join the conversation.

Start now!

Just create your account and start using Limesurvey today.

Register now
Join our Newsletter!