blic Posted June 9, 2011 Share Posted June 9, 2011 Hi All, I wanted to have in a page a link (or button) that, when clicked, called a function that would change some php variables. The piece of the the code would be someething like this: echo "<a href='#' onclick='foo()'><b>call foo</b></a>"; ?> <script> foo(){ <? $la = new MyClass(); $la->addver($ver); ?> } </script> <? I know this is not correct, so I was wondering if anybody has a simple solution to that. Cheers Quote Link to comment https://forums.phpfreaks.com/topic/238887-php-onclick/ Share on other sites More sharing options...
AbraCadaver Posted June 9, 2011 Share Posted June 9, 2011 Since PHP is server side then your link would need to call the same page and pass a parameter telling what function to call. This is just a rough example: echo "<a href='{$_SERVER['PHP_SELF']}?func=foo'><b>call foo</b></a>"; $safe_funcs = array('foo', 'bar'); if(isset($_GET['func']) && in_array($_GET['func'], $safe_funcs)) { $_GET['func'](); } function foo(){ $la = new MyClass(); $la->addver($ver); } Quote Link to comment https://forums.phpfreaks.com/topic/238887-php-onclick/#findComment-1227486 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.