[Javascript] calling js function from php

Steven Chipman sgchipman at gmail.com
Mon May 29 11:45:09 CDT 2006


On 5/29/06, suresh kumar <asureshkumar_1983 at yahoo.co.in> wrote:

> 1) i want to call a javascript function from php. this is my code.
> <script type="text/javascript">
>  function confirmask()
> {
>
>        var con=confirm("you are trying to cancel a mirrored display
> location.Do u want to continue");
>        if(con==true){
>          return 1;
>        }
>        else if(con==false){
>         return 0;
>
>        }
>
> }

The confirm method returns boolean, so you dont need to check its
state for true and then return true if it is. This will suffice:

return confirm("you are trying to cancel a mirrored display
location.Do u want to continue");

>
> <?
> $res=confirmask();
...snip
> 2)   how can i assign a  javascript variable to php

Why not just submit a form to a PHP script that does your database
action and then does your location.replace? For example:

document.forms[0].onsubmit = return confirm("are you sure?");

When a user activates the link or whatever you are using to call the
delete action, you can populate the form with the required ids, etc,
and then call the submit method of the form.


-- 
steve
http://slayeroffice.com



More information about the Javascript mailing list