I am trying to disable the function I pass to addEventListener
when the user clicks on submit. I put code in to prevent user from leaving page if they have entered
To prompt the user before leaving a form:
window.onbeforeunload = function(){ return 'Are you sure you want to leave?'; };
See this post
required
attribute on each field and you won't need to do all of that. The following demo will refuse any attempts to submit it's form if there's a blank field. It will send to a live test server and a response will be displayed verifying a successful submission.
window.onbeforeunload = function(){
return 'Are you sure you want to leave?';
};
label {
display: inline-block;
width: 75px
}
[type=submit] {
margin-left: 200px
}