Jump to content

combine PHP with Javascript


Recommended Posts

i write the function using php, but when i want to display msg box for confirmation, i used javascript. in confirmation box, if user choose yes, i want to execute the function that use PHP. can i write the script like that?

the script is like this:

echo "<script type=\"text/javascript\">var stay =confirm (\"Do You Agree?\");

if(stay)

here if the function using PHP

</script>";

how can i write the function of PHP in jscript ?

please help me.......

Link to comment
Share on other sites


Only possible way to pull that off is to make multiple requests to php itself. Which would result in multiple hits to the server. Just keep note that with PHP that once the script is accessed for a page you cannot make any additional requests to it while it's being processed. Whatever requests it has recieved for that session are what it's got to use.

However, here is a code snippet for what you have an idea for. With comments :)

<script>
//Check for whatever it is to be agreed upon
$stay=confirm ('Do You Agree?');

//Is 'agree' then reload the frame\page with this script
//but with the 'stay' request variable set as true
if($stay) top.location='this_script.php?stay=1';
</script>

<?php
if($_GET['stay']) //check if stay contains a value equating to true
{
//do whatever you want done here if stay === TRUE
}
?>

I personally use a more complex method in one of my scripts but requires frames to successfully pull it off. What happens there is that it rewrites a hidden frame requesting the php script as the script src which fetches any updated java from the server. Then when received that script is targeted to the main frames and executed. It's basically a dumbed down form of XMLRequest\Ajax but works on even legacy browsers without a hitch (IE4\NN4 for example) through DHTML.

Edited by Chozo4
Link to comment
Share on other sites

echo "<script type=\"text/javascript\">varn stay =confirm (\"Item: ".$F_item."\");
if(stay)
top.location='received.php?stay=1';

</script>";
<?
if($_GET['stay']) //check if stay contains a value equating to true

{
pilihPembekal($f_supp,$f_pem,&$dberror);
}
?>

here is my latest script, when i run it on server, the function of pilihPembekal () did not perform.

please u check it. is it right? i write this script based on ur example. :(

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...