PDA

View Full Version : Deleting with confirmation



ronny
07 Oct 2006, 01:28 PM
Hey guys,

I am making an administration section to a website, and i want the user to be able to delete records from the database.
Up to now i have had no problem. I managed to list all the records that are in the database and have a little delete image next to each record that links to a delete.php file which removes the chosen item from the database by passing the ID via the link.
For example if i wanted to delete record with the ID 1 the link will be delete.php?recordID=1

However, when the user clicks the delete image i want a message box to pop up to ensure the user really wants to delete the record.
I created a jscript message box:



function ss()
{
var x=window.confirm("Are you sure you want to delete this tip?")
if (x)
window.location="delete.php"
else
window.location="#"

}
</script>


and in the link i put


echo"<td><center><a href='delete_tip.php?delete_tip=$tip_id' onclick='ss()'><img src='imgs/b_drop.png' border='0' alt='delte tip'></a></center></td>";

This doesnt work, because even if the user chooses cancel the link still goes through :confused:

I know i am doing something wrong. maybe making this far to complicated than there is.

Is there a way to just stop the browser going to the next page?

Hope someone can understand me and help me out

TIA!!