0

Hey everyone, I have a question. I have a web app where you have a table that will either update, delete, or add a user. The update works great but the delete is weird. It deletes just fine, but I ask for a confirmation first before the action is completed.
I am using PHP, jquery/javascript, html, and MySQL
This is the code that I used for the button

 echo "<td><button type='submit' name='delete' value='".$row['UserID']."' class='delete-button'>Delete</button></td>";

This is the jquery/javascript that I am using

 $('.delete-button').on('click', function()
        {
                var conf=confirm("Are you sure?");
                if(conf==false)
                {
                        window.close();
                }
                       });
});

When the user hits the button, the popup comes out asking if they are sure. If they hit the cancel button, the window will close. If they hit okay, they will go to the next page where the Query will be executed to delete the entry.
However, sometimes but not all the time, the entry will be deleted even if the user hits the cancel button. Would anyone know why that is happening?

2
Contributors
2
Replies
20
Views
1 Year
Discussion Span
Last Post by TheFearful
1

I would guess it is because you're not actually stopping the button submission by return false; or event.stopPropagation() so your form is still submitting sometimes. All the cancel button does is close the window but you've still clicked the submit button before that.
Why it only happens sometimes, I don't know, probably a matter of timing before the window closes.

0

I did a preventDefault method and it worked perfectly! Thank you for the input!

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.