/    Sign up×
Community /Pin to ProfileBookmark

How to confirm before deletion through a submit button

Hi,

I have a submit button which deletes some checked out records on my web page.

Now I want to add a messagebox before deleting the records, but somehow it is not working.
Upon selection of either of ‘ok’ and ‘cancel’ , it is deleting the record. How can I make sure that
delete only when ‘ok’ is pressed and ‘Do not’ delete when ‘cancel’ is pressed ?

Following is my code :

[CODE]
$cgi->submit(-label => “Remove selected records”, -onClick => ‘confirmBeforeDeletion()’);

function confirmBeforeDeletion
{
var con = confirm(“Are you sure to delete”);
if(con == true)
{
form.submit;
}
else
{
return;
}
}[/CODE]

These above javascript function is not taking the appropriate action which I want. In both cases if and else, it is deleting the record.

Please help.

to post a comment
JavaScript

1 Comments(s)

Copy linkTweet thisAlerts:
@rh_lloydnorthovMar 07.2013 — I think you can shorten your function to:

[CODE]function confirmBeforeDeletion()
{
return confirm("Are you sure to delete");
}[/CODE]


if your function returns true (the user selects 'Yes') the form will submit as normal, while if the form returns false the form will not submit. The minimum change you need to do is replace the 'return' in the code you posted with 'return false' i.e.:

[CODE]function confirmBeforeDeletion
{
var con = confirm("Are you sure to delete");
if(con == true)
{

form.submit;
}
else
{
return false;
}
}[/CODE]
×

Success!

Help @myuser spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.12,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...