Grabeorama Posted December 21, 2008 Share Posted December 21, 2008 Is it possible to call a PHP function with 'onclick'?like if I had:<input type="button" onclick="php_function()" value="click">or would it have to be in JS? Link to comment Share on other sites More sharing options...
Wander Posted December 21, 2008 Share Posted December 21, 2008 once a page is loaded, the php on that page is finnished, however u can use ajax (javascript+xmlhttprequest) to request another page while u stay at the same page, for more info about this, see: http://w3schools.com/ajax/ Link to comment Share on other sites More sharing options...
Anman Posted December 21, 2008 Share Posted December 21, 2008 Is it possible to call a PHP function with 'onclick'?like if I had:<input type="button" onclick="php_function()" value="click">or would it have to be in JS?No, you cannot make a PHP function happen after the page is loaded. PHP is a Preprocessor. Link to comment Share on other sites More sharing options...
Grabeorama Posted December 21, 2008 Author Share Posted December 21, 2008 Ah, o.k.Thanks :)I'll just have to use javascript Link to comment Share on other sites More sharing options...
Ache Posted January 15, 2009 Share Posted January 15, 2009 I was facing the same problem and all I found was no for an answer. Well, surprise. Not exactly with onclick since that is JS, but there is way to basicly the same with PHP/HTMLHere is an example: <?phpfunction myfunction(){echo("<strong>I love PHP !</strong><br>");}?><a href="<?php echo("$PHP_SELF?execute=myfunction")?>">click to execute myfunction ! </a><p><?php if ( isset($execute) ){myfunction();}?> Link to comment Share on other sites More sharing options...
justsomeguy Posted January 19, 2009 Share Posted January 19, 2009 That's not really the same, JavaScript's onclick handler will execute a function without reloading the page, your code is just setting up a link, which obviously reloads the page. Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.