Re: calling user-defined php functions from <a href> tag

From: Date: Sat, 27 Jul 2002 01:35:23 +0000
Subject: Re: calling user-defined php functions from <a href> tag
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-109909@lists.php.net to get a copy of this message
on 27/07/02 12:09 PM, Michael (mlee@ni-solutions.com) wrote: > <?php > function joe() { > $temp1=10; > $temp2=20; > $result=$temp1+$temp2; > echo "The result of this function is: " . $result; > } > ?> wouldn't that be return "The result of this function is: " . $result; rather than echo? Anyhoo, you haven't specified HOW you want to communicate the result of the function to the browser. A HREF is supposed to take you off to another page (amongst other things), which might be what you're after. JavaScript (*shudder*) is designed to provide client-side actions, so maybe a javascript alert is what you want, or a pop-up window, or who knows what. You need to decide what happens, in a story board fashion. Remember, everything in PHP code takes place on the server, BEFORE the browser gets it. Example of using JS alert: <HTML> <? function joe() { $temp1=10; $temp2=20; $result=$temp1+$temp2; return "The result of this function is: " . $result; } ?> <A HREF="#" onclick="javascript:alert('<?=joe()?>')">calculate foo</a> </HTML> but really, I can't understand why you wouldn't just do: <HTML> <? $result=$temp1+$temp2; echo "Total: {$result}"; ?> </HTML> Why do they have to click? You'll have to check all the javascript stuff and maybe massage it, because I haven't tested this, and haven't written much JS in the past coupla years. Beware of the limitations of relying on javascript for anything though :) Justin French

« previous php.general (#109909) next »