I'm trying to figure out how to have a Confirm/Decline box pop up when someone clicks a link. When they click "Ok" it takes them to one place, when they click "Cancel" it takes them to another place. Most of my experience is with PHP but usually I can take other JavaScript functions and make them work... can't seem to figure this one out though.
Here's my script:
function confirmChoice(name, newid){
answer = confirm("Transfer Ownership of this task to " + name +
"? Press Cancel to decline.")
if (answer == 1) {
location = "transfer.php?task=<? echo $taskid; ?>&from=<? echo ownerid; ?>&to=" + newid;
} elseif (answer==0) {
location = "decline.php?task=<? echo $taskid; ?>";
}
}
Any help would be greatly appreciated!
EDIT: Okay, changed the code as suggested. Now it is:
function confirmChoice(name, newid){
var answer = confirm("Transfer Ownership of this task to " + name + "? Press Cancel to decline.")
if (answer){
location = "transfer.php?task=<? echo $thistaskid; ?>&from=<? echo $ownerid; ?>&to=" + newid;
}else{
location="decline.php?task=<? echo $thistaskid; ?>";
}
}
And the link used is:
<a href="#" onclick="confirmChoice(<? echo $requestorname; ?>, <? echo $newid; ?>); return false;"><? echo $requestorname; ?> Requested Ownership</a>
I still don't get a confirm box...