-2
/*
//Want to call a php function when on clicking a tag
// Want to call a php function when on clicking a tag
//Want to call a php function when on clicking a tag
// Want to call a php function when on clicking a tag
*/


<?PHP 
//starting of a function
function callfun(id)
{
//prints the parameter of the function
echo id;
}

//call a php function when clicks on a paragraph
echo '<p id="xyz" onClick="callfun(id)">Click Me </p>';

?>
/*Want to call a php function when on clicking a tag
Want to call a php function when on clicking a tag
Want to call a php function when on clicking a tag
Want to call a php function when on clicking a tag

*/
Quentin
  • 914,110
  • 126
  • 1,211
  • 1,335
  • You should postload a php file using a XHRC – das_j Mar 05 '14 at 09:13
  • 3
    PHP is a preprocessor, so it modifies the page and sends the modified result to the Browser. So when the client receives the page, there is no PHP in it anymore. That is the reason why you should load a .php file using JavaScript and echo the output. – das_j Mar 05 '14 at 09:14
  • you have to handle click events using jquery & ajax on client side – MAK Mar 05 '14 at 09:14
  • So there is no way to do only with php i mean to say we cant call a php function on any event of HTML MAK and das_j – Sudhakar Singajogi Mar 05 '14 at 09:16

2 Answers2

0

You can use some technology to do this. One way is to call another script using ajax call for example. If you don't know what ajax is here is an explanation http://bg.wikipedia.org/wiki/Ajax

Another think you can try is just using javascript and translate your function in javascript.

0

PHP is not working like that. I suggest you to watch some tutorials about the language technique. First of all you need to understand the difference between the server side and the client side. PHP is not running on the client side! For your need you must use AJAX function which will call a request to the server.That request will execute the PHP function and return the answer to the clients browser.After that you can handle it for your needs.

ventsi.slav
  • 334
  • 1
  • 4
  • 14