Jump to content

Pop-up box confirmation problem


unistake

Recommended Posts

Hi all,

 

I have a link that when clicked I it shows a popup box and depending on whether the user clicks yes or no the user script will continue to a php processing page to delete a record.

 

I have made the popup box as shown below but if you click yes OR no the record is still deleted! How can I cancel the page being redirected if the user clicks no?

 

Thanks

 

<head>
</style>
<script type="text/javascript">
<!--
function confirmation() {
var answer = confirm("Are you sure you want to delete the advert?")
if (answer){
	alert("Your advert has been deleted!")
}
else{
}
}
//-->
</script>
</head>
<body>
<?php
echo "<a href=\"manage-aircraft.php?reg=$reg\">$title</a> <a href=\"works/deleteadvert.php?reg=$reg\" onclick=\"confirmation()\"><img src=\"images/delete.png\" alt=\"Aircraft For Sale\" width=\"15\" height=\"15\" /></a><br>";
?>
</body>

Link to comment
Share on other sites

you have no return so the link will always go through.

 

function confirmation() {
var answer = confirm("Are you sure you want to delete the advert?")
if (answer){
	alert("Your advert has been deleted!");
return true;
}
else{
return false;
}
}

 

I usually just do this:

<a href="link" onClick="return confirm('Are you sure you want to delete the advert?');">Link</a>

 

Link to comment
Share on other sites

Actually it works, however it does not delete the record in mysql. It was working fine before I put this popup box confirmation in so the code is good.

 

I think it may have something to do with this line:

<?php echo "<a href=\"manage-aircraft.php?reg=$reg\">$title</a> <a href=\"works/deleteadvert.php\" onClick=\"return confirm('Are you sure you want to delete the advert?');\"><img src=\"images/delete.png\" alt=\"Aircraft For Sale\" width=\"15\" height=\"15\" /></a><br>"; ?> 

 

The $reg value is not being passed on to the deleteadvert.php page.

 

Do you know why the $reg value would not be passed to the processing page with this alert box?

 

Thanks

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.