How to call a JavaScript function from PHP?
The followi
You may not be able to directly do this, but the Xajax library is pretty close to what you want. I will demonstrate with an example. Here's a button on a webpage:
Our intuitive guess would be that xajax_addCity()
is a Javascript function, right? Well, right and wrong. The cool thing Xajax allows is that we don't have any JS function called xajax_addCity()
, but what we do have is a PHP function called addCity()
that can do whatever PHP does!
Think about it for a minute. We are virtually invoking a PHP function from Javascript code! That over-simplified example was just to whet the appetite, a better explanation is on the Xajax site, have fun!