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

  • MSMSEVN
  • MSMSEVN's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
6 years 8 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.
  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
6 years 8 months ago - 6 years 8 months ago #156153 by tpartner
Replied by tpartner on topic How to creates pop-ups messages before submit
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: 6 years 8 months ago by tpartner.
The topic has been locked.
  • holch
  • holch's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
6 years 8 months ago #156155 by holch
Shouldn't this go into the javascript file rather the template.css?

I answer at the LimeSurvey forum in my spare time, I'm not a LimeSurvey GmbH employee.
No support via private message.

The topic has been locked.
  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
6 years 8 months ago #156156 by tpartner
Replied by tpartner on topic How to creates pop-ups messages before submit
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.
  • MSMSEVN
  • MSMSEVN's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
6 years 8 months ago #156194 by MSMSEVN
Replied by MSMSEVN on topic How to creates pop-ups messages before submit
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!
Attachments:
The topic has been locked.
  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
6 years 8 months ago #156202 by tpartner
Replied by tpartner on topic How to creates pop-ups messages before submit
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.

Lime-years ahead

Online-surveys for every purse and purpose