NYCPHP Meetup

NYPHP.org

[nycphp-talk] javascript calling php function

Anirudh Zala arzala at gmail.com
Mon Feb 18 06:02:13 EST 2008


On Monday 18 Feb 2008 15:53:24 Susan Shemin wrote:
> I want to use javascript onclick to call a php function.  This code works,
> but puts a "done, with errors" in the status line in the file when loaded,
> which I do not want.  (I've done some error testing and isolation, and
> found the onclick is what is causing the "errors" message.)  Any ideas --
> or other ways to do it?
>
> onclick="<?php here_it_is(); ?>";
>
> Also, I tried onclick=""; to make sure that it's the "embedded" php code
> that's the culprit, thinking that maybe javascript is reading the php code
> as nothing inside the quotes.
>
> Susan

You can't call PHP functions using JS like this. You need to use Ajax 
mechanism to call PHP function from your JS code.

I dobut whether it is working, as you said above, the way you wanted or not 
unless output of PHP function is valid JS code.

Also check your source code of your page to see what it reads 
between 'onclick=""' once page is loaded in browser.

Thanks

Anirudh Zala



More information about the talk mailing list