开发者

Breaking a PHP code with Javascript confirm dialog?

开发者 https://www.devze.com 2022-12-24 02:12 出处:网络
I have PHP scrip that goes like this: if ($cost_frm < $cost){ echo \"<script type=\'text/javascript\'>

I have PHP scrip that goes like this:

if ($cost_frm < $cost){
     echo "<script type='text/javascript'>
     var r = confirm('Input cost is lower than original. Sure?'));
     If (r==true){
            } else{
                            *** BREAK PHP SCRIPT ***
                           }
            开发者_运维知识库 </script>";
 }

And I'd like to stop ejecuting the script (or doing anything else) if the user clicks Cancel. Any tip?


You can't! PHP is server side, javascript is client side


Why not just put that entire validation into javascript?


Well I suppose if instead of running the whole script you broke it up into segments that you could activate using ajax, that might get you what you need.


You can't do that because the PHP is going to finish processing before the JavaScript runs.

PHP runs completely on the server, and only when it is done does it send the output to the browser, which then processes it. So by the time that box pops up, everything will be done.

0

精彩评论

暂无评论...
验证码 换一张
取 消