Welcome to the LimeSurvey Community Forum

Ask the community, share ideas, and connect with other LimeSurvey users!

How to creates pop-ups messages before submit

More
8 years 2 months ago #156136 by MSMSEVN
A few of participants close the survey by close web page, not submitted. I want to make a pop-ups message to ask them:"U've undone this survey. Are you sure you want to quit?" How to do that?
Many thanks
The topic has been locked.
More
8 years 2 months ago - 8 years 2 months ago #156153 by tpartner
You can use the "beforeunload event, although the behaviour is not standardized across browsers.

Add something like this to the end of template.js:

Code:
$(document).ready(function(){  
 
  $(window).bind("beforeunload", function(event) {
    return "Your data will not be saved!";
  });
 
  $('#movenextbtn, #movesubmitbtn').on('click', function () {
    $(window).unbind("beforeunload");
  });
});

Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
Last edit: 8 years 2 months ago by tpartner.
The topic has been locked.
More
8 years 2 months ago #156155 by holch
Shouldn't this go into the javascript file rather the template.css?

Help us to help you!
  • Provide your LS version and where it is installed (own server, uni/employer, SaaS hosting, etc.).
  • Always provide a LSS file (not LSQ or LSG).
Note: I answer at this forum in my spare time, I'm not a LimeSurvey GmbH employee.
The topic has been locked.
More
8 years 2 months ago #156156 by tpartner
Oops, yes, of course.

Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
The topic has been locked.
More
8 years 2 months ago #156194 by MSMSEVN
Thank for your response. But I still have a problem with pop-ups message. My survey is non-anonymous survey,so when I add this code to template.js, It's only appear on the register page (attached file). From welcome page to last page, It doesn't work. What can I do next?
Thanks in advance!
The topic has been locked.
More
8 years 2 months ago #156202 by tpartner
Try this:

Code:
$(document).ready(function(){  
 
  if($('#movenextbtn, #movesubmitbtn').length > 0) {
    $(window).bind("beforeunload", function(event) {
      return "Your data will not be saved!";
    });
 
    $('#movenextbtn, #movesubmitbtn').on('click', function () {
      $(window).unbind("beforeunload");
    });
  }
});

Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
The topic has been locked.
Moderators: tpartnerholch

Lime-years ahead

Online-surveys for every purse and purpose