0

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";
}
Jørgen R
  • 10,568
  • 7
  • 42
  • 59

3 Answers3

0

Javascript:

function confirm_delete() {
      return confirm('are you sure?');
    }

Use onclick in the button

onclick='return confirm_delete()'

When the user clicks OK the php code gets excecuted but when clicked on Cancel nothing happends.

Michel
  • 38
  • 1
  • 7
0

Why don't you use onclick?

onclick="return confirm('Are you sure you want to delete?');"

Alek_86
  • 45
  • 1
  • 5
0

The best way to do this is by onclick method as follows:

oncllick ='return confirm()'

function confirm()
{
    return confirm('Are you sure to continue?');
}

when user click ok then code excecuted and when click on cancel button it remains on that page only

varad mayee
  • 619
  • 7
  • 19