PDA

View Full Version : Help with link and confirm


Crashin
11-26-2002, 04:05 PM
I've got a link:
<a href="index.php?go=1&&id=<?php echo $row['id']; ?>" onClick="return confirm_delete();">Delete</a>
That calls the function:
function confirm_delete() {
var choice = confirm("Are you sure you want to delete the album?");
if (choice == true) {
return true;
}
else {
<?php unset($_GET['go']); ?>
return false;
}
}

However, when "OK" is selected it just reloads the index page. It's not passing on the variables in the link (i.e. ?go=1&&id=<?php echo $row['id']; ?>). The go variable tells the index page what to do (i.e. delete the associated record). Thanks in advance for the help!

beetle
11-26-2002, 04:17 PM
Ok, your function isn't doing anything fancy...you can just use this instead....

<a href="index.php?go=1&&id=<?php echo $row['id']; ?>" onClick="return confirm('Are you sure you want to delete the album?'); ">Delete</a>

As far as the unset($_GET['go'])....I'm not sure why you placed that code where you did? All PHP processes take place before the HTML page is sent to the browser, so placing PHP code inside Javascript syntax like this makes no sense...

Crashin
11-26-2002, 04:24 PM
Thanks for the reply. Your suggestion was originally how I had the link setup, however I re-placed the method in the link as shown:

<a href="index.php?go=1&&id=<?php echo $row['id']; ?>" onClick="return confirm('Are you sure you want to delete the album?'); ">Delete</a>

And am still getting the same result. Any ideas?

Crashin
11-26-2002, 04:43 PM
I beg your pardon...I don't know why, because I SWEAR I tested it before re-posting, but it is working now. Go figure. Thanks again!