tags:

views:

46

answers:

4

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  A: 

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

AntonioCS
Well...in *this* case it is, yes. :-)
T.J. Crowder
@t.j crowder: hell, do you know some cases where php run client-side and javascript run server-side? let me know ;)
DaNieL
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
Carson Myers
There are several implementations of server side JavaScript. Aptana Jaxer and Rhino at least, iirc. Client side PHP? Not yet.
Macha
+1  A: 

Why not just put that entire validation into javascript?

Todd
A: 

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.

Tyler Smith
+1  A: 

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.

Mike Gensel
+1 AJAX makes interfacing javascript and PHP sort-of possible, and this is often overlooked.
Carson Myers