phppup Posted January 3, 2019 Share Posted January 3, 2019 (edited) I am trying to implement a CONFIRMATION dialogue box before the processing of a form. The dialogue box uses some variables from a previous script, so it seems that calling the confirmation box needs to be done through a function. And it seems that using a function to address the "action" is a tiny bit more complicated than just slapping a confirmation into the element. My issue at this point is an inability to direct to the processing.php page function confirm() { if(confirm("Are you sure you want to do this with $blah1 $blah2 $blah3 )== true) { window.location.href = "https://www.example.com"; //would actually be "processing.php" } else { return false; } } The browser shows an indication of 'thought' but will not advance to the next page (or an error page) - it simply refreshes. Oddly, when I modified the end of the script to say this, it seemed to work } else { return false; alert("bye"); } } (but I don't understand why). Answers? Solutions? Remedies? Explanations? Please enlighten me. Edited January 3, 2019 by phppup Quote Link to comment https://forums.phpfreaks.com/topic/308101-something-odd-about-this/ Share on other sites More sharing options...
requinix Posted January 3, 2019 Share Posted January 3, 2019 Assuming you have a form somewhere like <form id="whatever" action="processing.php" method="post"> and aren't using a Javascript library, add an event listener for the form submission like document.getElementById("whatever").addEventListener("submit", function(e) { if (!confirm("Are you sure you want to do this with $blah1 $blah2 $blah3")) { e.preventDefault(); } }); Quote Link to comment https://forums.phpfreaks.com/topic/308101-something-odd-about-this/#findComment-1563259 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.