jbingman Posted October 2, 2007 Share Posted October 2, 2007 I have a php/mysql script that i have update information in a mysql database and when the user clicks "save" they should get a confirm box asking if they want to continue. How can i integrate this javascript into PHP? Quote Link to comment https://forums.phpfreaks.com/topic/71462-solved-javascript-confirm-box-in-php/ Share on other sites More sharing options...
RichardRotterdam Posted October 2, 2007 Share Posted October 2, 2007 Ok so if I am right you want this (not working example) you have a button which calls a function <button onClick="save">a button</button> this calls a function <script> function save(){ var confirmSaveBox=confirm("do you wish to save"); if(confirmSaveBox==true){ //alert('save'); //call php page to update mysql } } </script> now do you want this to happen without refreshing the page? or do you wish to redirect to a page submitting the values with a form Quote Link to comment https://forums.phpfreaks.com/topic/71462-solved-javascript-confirm-box-in-php/#findComment-359763 Share on other sites More sharing options...
jbingman Posted October 2, 2007 Author Share Posted October 2, 2007 Yes thats exactly what i want. Quote Link to comment https://forums.phpfreaks.com/topic/71462-solved-javascript-confirm-box-in-php/#findComment-359766 Share on other sites More sharing options...
RichardRotterdam Posted October 2, 2007 Share Posted October 2, 2007 with or without refreshing the page? if you want this to happen without a refresh you'll need an ajax funtion Quote Link to comment https://forums.phpfreaks.com/topic/71462-solved-javascript-confirm-box-in-php/#findComment-359769 Share on other sites More sharing options...
jbingman Posted October 2, 2007 Author Share Posted October 2, 2007 um without refreshing the page. so once they fill in the values in the form, it will submit then to the mysql database if they click "ok" and keep them on the same page if they click "cancel". Quote Link to comment https://forums.phpfreaks.com/topic/71462-solved-javascript-confirm-box-in-php/#findComment-359778 Share on other sites More sharing options...
nikkieijpen Posted October 2, 2007 Share Posted October 2, 2007 Javascript (put it in the 'head' tag): <script language="javascript" type="text/javascript"> function saveForm(){ var confirmSaveBox = confirm("Do you wish to save?"); if(confirmSaveBox == true){ document.form1.submit(); } } </script> HMTL: <form name="form1" action="save.php"> <input type="button" value="Save!" onClick="saveForm();" /> </form> Quote Link to comment https://forums.phpfreaks.com/topic/71462-solved-javascript-confirm-box-in-php/#findComment-359950 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.