开发者

How to set up flag in wizard form to allow submit/override other function

开发者 https://www.devze.com 2023-01-03 18:01 出处:网络
Hi I have a long form that is split into a wizard. To prevent the user from hitting browser back button and losing data I have the following:

Hi I have a long form that is split into a wizard. To prevent the user from hitting browser back button and losing data I have the following:

window.onbeforeunload = function() { return "Hitting back will cause you to lose all form data."; };

How would I insert a flag and apply to th开发者_运维知识库e last step so the form can be submitted properly? Thanks,


You can set a variable on the last step to true and check against it, like this:

var okToSubmit = false;
window.onbeforeunload = function() { 
  if(!okToSubmit) return "Hitting back will cause you to lose all form data."; 
};
//set okToSubmit = true; on the last step

Without your current code I can't say exactly where to insert this, but wherever your script moves to the last step, add a okToSubmit = true; in there.

0

精彩评论

暂无评论...
验证码 换一张
取 消