I have created a Joomla article. I have installed sourcerer Joomla extension to use JavaScript and php. I am working on course purchase site in this user purchase course from owner and credits are deducted on purchasing of course. We are using a confirm box so that when a user click on "Cancel" button then it return to course page and when user click on "OK" button, then a php code is executed and course is purchased and credits are deducted. It works fine when I click on the OK button. When I click on cancel button, it is deducted credits also. I don't want to deduct credits on click of cancel.
I am using this JavaScript code:
var answer = confirm ("You are about to purchase this course. Click Continue to complete the purchase, or CANCEL to return to the CE page.");
if(!answer)
{
window.location="index.php";
}