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
  • eirikat's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
6 years 7 months ago #158594 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:
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
  • tpartner's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
6 years 7 months ago #158609 by tpartner
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
  • eirikat's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
6 years 7 months ago #158611 by eirikat
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.
The topic has been locked.
  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
6 years 7 months ago #158670 by tpartner
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.
The topic has been locked.
  • eirikat
  • eirikat's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
6 years 7 months ago #158688 by eirikat
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.

Lime-years ahead

Online-surveys for every purse and purpose