I want to deactivate the form temporarily and display a confirmation box whether the data wants to be sent or not, but I have problems when I want to activate the form again.
Code to deactivate form :
var statusForm = true;
$("form.form-update").submit((e)=>{
e.preventDefault();
$("form.form-update input").each((key, element) => {
if (element.value == "") {
statusForm = false;
}
});
if (statusForm == false) {
alert("Data is invalid!");
}
else{
// Show the popup
$(".confirm-notification").show();
}
})
Code when "yes" button is clicked :
// When "yes" button click
$(".confirm-notification-yes").click(()=>{
// Code to remove preventDefault() on $("form.form-update")
})
How to remove preventDefault() on $("form.form-update")?
[Problem solved] Problem was solved with combined the unbind() and submit() method. So the code became :$(".confirm-notification-yes").click(()=>{
$("form.form-update").unbind('submit');
$("form.form-update").submit();
})
2
Answers
do it like that
On "Yes", submit the form:
Now, let’s fix the first part. I suppose submission is started through a button. You put your code in that button, not the submit event.