coupe-r Posted September 17, 2010 Share Posted September 17, 2010 I am trying to display a js dialog box when someone wants to delete something. Currently I have it all with buttons and PHP in the background. When they click the delete icon, I want a dialog box to appear with OK or Cancel. On cancel, return back to the same page, If OK, I want it to run the PHP/mysql code that deletes the record from the DB. Once deletes, I want the box to appear again saying it was deleted successfully. I found this but now sure how to make it work. function show_confirm() { var r=confirm("Press a button"); if (r==true) { alert("You pressed OK!"); } else { alert("You pressed Cancel!"); } } Quote Link to comment Share on other sites More sharing options...
iainwood Posted September 17, 2010 Share Posted September 17, 2010 You would have to be looking at ajax here. It's pretty simple 1 call function 2 if they confirm call the ajaxfunction 3 when the ajax function is complete call the alert box again this should help ajaxget("delete.php?id=xxxx","resultsDiv","confirmdelete") function confirmdelete(){ alert("Delete Done"); } function ajaxget(url,outputid,funcToCall){ var AJAX; try { AJAX = new XMLHttpRequest(); } catch(e) { try { AJAX = new ActiveXObject("Msxml2.XMLHTTP"); } catch(e) { try { AJAX = new ActiveXObject("Microsoft.XMLHTTP"); } catch(e) { alert("Your browser does not support AJAX."); return false; } } } AJAX.onreadystatechange = function() { if(AJAX.readyState == 4) { if(AJAX.status == 200) { //execute the function eval(funcToCall + '()'); //write the resulting html to the div (or whatever) document.getElementById(outputid).innerHTML=AJAX.responseText; } else { alert("Error: "+ AJAX.statusText +" "+ AJAX.status); } } } AJAX.open("get", url, true); AJAX.send(null); } Quote Link to comment Share on other sites More sharing options...
Adam Posted September 17, 2010 Share Posted September 17, 2010 I'd go with a different AJAX handler though, no offence iainwood. Quote Link to comment 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.