solarisuser Posted December 28, 2006 Share Posted December 28, 2006 Hello All,I have incorporate a little javascript to show a confirm dialog box. The problem I have is when the user clicks on the Cancel button (instead of the OK button), the page seems to do the URL transfer, but it still processes the rest of the PHP page. I'd like to abort the page if the user clicks on cancel.I put in an "exit(0);" like I would do in PHP, but it still processes the rest of the code.One way I can think of getting around this is to set a variable like $abort to '1' after window.location(), but how do I get PHP to read the JS variable?ThanksHere is my code:[code]$sol = "testname";if(isset($sol) && ($sol != '')) {echo " <SCRIPT type=\"text/javascript\"> <!-- hostname = '$hostname'; var answer = confirm (\"Your hostname is \"+hostname+\". Is this correct?\") if(!answer) { window.location = (\"index.php\"); exit(0); } //--> </script>"; }[/code] Link to comment https://forums.phpfreaks.com/topic/32101-how-to-exit-if-javascript-code-returns-a-value/ Share on other sites More sharing options...
Shu Posted December 28, 2006 Share Posted December 28, 2006 when the person press cancel, nothing is send to the server. so php won't even know. Link to comment https://forums.phpfreaks.com/topic/32101-how-to-exit-if-javascript-code-returns-a-value/#findComment-148969 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.