Jump to content

simple confirmation button question


Alkimuz

Recommended Posts

i'm a little ashamed to asked something that is probably so easy, i tried to find the answer, but i am really a NOOB in javascript so i hope that i can ask you for a code that is ready to use..

 

i now have a code to delete an item in a website by pushing on a button. It goes to a new page wich has an SQL delete code. 

 

In short:

echo '<a href="save.php?type=delete&item='.$item.'">delete</a> ';

 

but now i really like to put a confirmation box between that, so after pushing the button, a message box appears asking: "Are you sure to delete this item?" and after clicking yes, it goes right away to that deletepage

 

thanks very much in advance!

 

Link to comment
Share on other sites

Don't worry about it, everyone's been there.

 

From within the onclick attribute of your link, call your confirmDelete() type function:

 

echo '<a href="save.php?type=delete&item='.$item.'" onclick="return confirmDelete();">delete</a> ';

 

Be sure to include the return part as this will prevent the page from redirecting if the return is false.

 

Then your confirmDelete() function needs to be something like:

 

function confirmDelete() {
    var c = confirm('Are you sure you want to delete this item?');
    if (!c) return false;
}

 

Then that should be it. Although you should be aware not everybody has JS enabled, so that confirmation message won't appear for everyone.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.