newphpbees Posted December 19, 2011 Share Posted December 19, 2011 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 Quote Link to comment https://forums.phpfreaks.com/topic/253453-confirm-box-before-saving-data/ Share on other sites More sharing options...
jotorres1 Posted December 19, 2011 Share Posted December 19, 2011 You need to have a form first, then do this <script language="javascript"> function confirmMySubmit(theForm){ if(confirm("Ready?")){ theForm.submit(); } } </script> <form action="http://www.jotorres.com"> <input type ="button" name="GENERATE_DATA" value="GENERATE DATA" onclick="confirmMySubmit(this.form);"> </form> Quote Link to comment https://forums.phpfreaks.com/topic/253453-confirm-box-before-saving-data/#findComment-1299125 Share on other sites More sharing options...
newphpbees Posted December 19, 2011 Author Share Posted December 19, 2011 I tried this code: <input type="button" name="GENERATE_PAYROLL" value="GENERATE PAYROLL" style="width: 200px;" onclick="return confirm('Do you want to save the data')"> my problem now, I don't know where i can add the syntax or condition, that if I press OK it will save the data or if I press cancel it will close the confirm box. Thank you Quote Link to comment https://forums.phpfreaks.com/topic/253453-confirm-box-before-saving-data/#findComment-1299140 Share on other sites More sharing options...
haku Posted December 19, 2011 Share Posted December 19, 2011 You already did that. Quote Link to comment https://forums.phpfreaks.com/topic/253453-confirm-box-before-saving-data/#findComment-1299145 Share on other sites More sharing options...
newphpbees Posted December 19, 2011 Author Share Posted December 19, 2011 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 Quote Link to comment https://forums.phpfreaks.com/topic/253453-confirm-box-before-saving-data/#findComment-1299153 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.