Jump to content

Recommended Posts

Hello

I want to show an alert or confirmation when somebody click on "delete" button.  There are many examples on line and I have read at least 10 posts on some exchange website which sadly has never worked for me (those of you who are old users of internet probably remember a stupid website called expertvillage.  This expertexchange sites must be related).

The code is pretty straight forward and it actually generate a confirm alert but no matter which option the viewer clicks it goes ahead and deletes (send the viewer to a page that deletes).  Just as if there was no confirmation alert at all.

I do not know JS and frankly never liked it, but I think it not working has more to do than just me not liking the language.

Here is a code, any idea or suggestions is highly appreciated:

<form action=deletetest.php method=POST>

<input type=submit value=\"Delete records\" onclick=\"ConfirmDelete()\">

</form>

<script>

function ConfirmDelete()

    {

    return confirm("Are you sure you want to delete?");

    }

</script>

 

 

Edited by PHP5000
Link to comment
https://forums.phpfreaks.com/topic/325727-example-of-a-functional-confirm-delete/
Share on other sites

The "expert sex change" website still exists? Wow. That's amazing.

The way for this (dated) design to work is that onclick has to return true/false. Right now, all it does is execute a function. Yes, that function returns true/false itself, but nothing happens with that value. It's just like writing

function onclick() {
  ConfirmDelete();
}

You should try to do Javascript the modern way, which is "modern" for very good reasons, but if you won't then you fix this problem by making the onclick code "return" a value.

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.