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.
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.
function generatepay(){
if (confirm("Are you sure do you want to generate payroll"))
{
window.location="generate_payroll.php";
}
else
{
window.location = "payroll_category.php";
}
}
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.