NYCPHP Meetup

NYPHP.org

[nycphp-talk] javascript calling php function

Steve Manes smanes at magpie.com
Mon Feb 18 10:18:47 EST 2008


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.

Javascript is client side and PHP is server side.  Javascript's 
'onclick' can only call a function within Javascript's namespace, not a 
function living on the server.  You may find this easier done with a 
library like xAjax which wraps PHP functions for Javascript calls using XML.




More information about the talk mailing list