newphpcoder — 2011-12-18T20:26:44-05:00 — #1
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
chris_upjohn — 2011-12-18T21:08:34-05:00 — #2
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')">
newphpcoder — 2011-12-18T21:33:00-05:00 — #3
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.
chris_upjohn — 2011-12-18T21:40:41-05:00 — #4
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.
newphpcoder — 2011-12-18T21:56:40-05:00 — #5
I resolved it using this code:
if (confirm("Are you sure do you want to generate payroll"))
window.location = "payroll_category.php";
chris_upjohn — 2011-12-18T22:15:41-05:00 — #6
Glad you worked it out bud
felgall — 2011-12-19T03:04:11-05:00 — #7
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.
newphpcoder — 2011-12-19T03:06:04-05:00 — #8
how can I create a lightbox?I'm nort familiar on that..