Javascript Confirm On Form Submit Not Canceling
I have a pretty simple Javascript function I want to include in a form (submit or cancel). The problem is it's supposed to cancel the form submit if I push cancel. Right now it jus
Solution 1:
Change it to
function confirmdelete()
{
return confirm("Deleting this answer may cause dataloss, are you sure you want to continue?")
}
Solution 2:
Fixed the issue by putting
onsubmit="return confirmdelete()"
Instead of
onsubmit="confirmdelete()"
That was the main issue, also used some of Rob's updates above for the final Javascript function... Thanks!
function confirmdelete() {
var r=confirm("Deleting this answer may cause data loss, are you sure you want to continue?");
if (r==true)
{
returntrue;
}
else
{
returnfalse;
}
}
Solution 3:
You need to combine the confirm with an if
statement:
function confirmdelete() {
if(confirm("Deleting this answer may cause dataloss, are you sure you want to continue?")({
returntrue;
} else {
returnfalse;
}
}
You can also do the return
that @mmillican recommended (much shorter, nice and simple), I just usually do the if
statement in case you want to do some extra magic. Either one works. :)
Solution 4:
Need to assign the confirm and return it
var confirmed = confirm("Deleting ...
return confirmed;
return false;
is what stops the form submit
Post a Comment for "Javascript Confirm On Form Submit Not Canceling"