- Posts: 16
- Thank you received: 3
Welcome to the LimeSurvey Community Forum
Ask the community, share ideas, and connect with other LimeSurvey users!
Save entered responses to database using jquery
- eirikat
- Topic Author
- Offline
- New Member
Less
More
6 years 6 months ago #158594
by eirikat
Save entered responses to database using jquery was created by eirikat
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:
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+
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:
Code:
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+
The topic has been locked.
- tpartner
- Offline
- LimeSurvey Community Team
Less
More
- Posts: 10611
- Thank you received: 3690
6 years 6 months ago #158609
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 Save entered responses to database using jquery
Try this (untested):
Code:
$( "#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
The topic has been locked.
- eirikat
- Topic Author
- Offline
- New Member
Less
More
- Posts: 16
- Thank you received: 3
6 years 6 months ago #158611
by eirikat
Replied by eirikat on 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.
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.
The topic has been locked.
- tpartner
- Offline
- LimeSurvey Community Team
Less
More
- Posts: 10611
- Thank you received: 3690
6 years 6 months ago #158670
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 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.
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.
The topic has been locked.
- eirikat
- Topic Author
- Offline
- New Member
Less
More
- Posts: 16
- Thank you received: 3
6 years 6 months ago #158688
by eirikat
Replied by eirikat on 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
The topic has been locked.