Alert/Confirm box for saving data

Hi…

I have a button to generate data or save all data in the database.

Now, I want that when i click the button to generate data it will not save all data, i want first appear an alert or confirm box asking if “Do you want to save data?” and i want it has a OK and Cancel…when the OK was pressed it will automatically save data and when the Cancel was pressed the alert/confirm box will closed?

Is it possible?

Can you give me an idea or example…But now i searching also for that.

here is my code:


<input type="button" name="GENERATE_DATA" value="GENERATE DATA" style="width: 200px;">

and i have a php file for saving data…

Thank you so much

In the most simple form you can use a confirm declaration which by default has an OK and CANCEL button, see the below example:

<input type="button" name="GENERATE_DATA" value="GENERATE DATA" style="width: 200px;" onclick="return confirm('Do you want to save the data')">

Yes, I tried also that code…But it has no condition that if i press OK it will save data and if i press cancel it will closed the confirm box.

Thank you

Does your button reside in a <form> element? If it doesn’t it would be best to have it wrapped in one as the example above will either cancel or allow the data to be sent, if you cannot have a form running for any reason another way would to create a function that checks the confirm status and then connects to your PHP script if the given button selection is OK.

I resolved it using this code:


function generatepay(){
 if (confirm("Are you sure do you want to generate payroll"))
        {
        window.location="generate_payroll.php";


        }

        else
        {
      window.location = "payroll_category.php";


        }
}

Thank you

Glad you worked it out bud

Just remember that as that dialog box is intended for debugging that it also has an option for turning off JavaScript in some browsers and turning off all further debugging type dialog boxes in some others.

If you don’t want to present people with that third option in the browsers that make the debugging tools more useful by providing them then you should create your own lightbox form instead.

how can I create a lightbox?I’m nort familiar on that…

Thank you