0

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?

4 Answers 4

4

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

Sign up to request clarification or add additional context in comments.

4 Comments

Well...in this case it is, yes. :-)
@t.j crowder: hell, do you know some cases where php run client-side and javascript run server-side? let me know ;)
you can certainly run PHP on in an interpreter, and I'm sure there is a javascript interpreter independent of a browser. Imagine -- downloading a PHP script which uses curl to connect to a server on a port, which executes some javascript and returns the result. I almost want to try it
There are several implementations of server side JavaScript. Aptana Jaxer and Rhino at least, iirc. Client side PHP? Not yet.
1

Why not just put that entire validation into javascript?

Comments

1

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.

1 Comment

+1 AJAX makes interfacing javascript and PHP sort-of possible, and this is often overlooked.
0

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.