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

From: Date: Sat, 27 Jul 2002 02:43:35 +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-109911@lists.php.net to get a copy of this message
Hi, Justin. Thanks very much for the reponse. Yeah, this is a SUPER simplified form of my question, so please don't expect it to make sense. Heh. Basically, I have a php file with dozens of functions in it. I want ONE of them to get called when a link is clicked. Currently, I achieve this with the use of HTML forms. My form generates a list of options. And the user has to select an option, then click the SUBMIT button. But I want to make it a one-step process, whereby the user only needs to click on the option. Of course, you can't achieve this in a form with JavaScript, but the JavaScript code won't let me execute a server-side php function (obviously). And I don't want to just shoot the link off to another page (even though that's what it was designed to do). I want to call a very specific function. Tricky, I know. :( -- Michael On Sat, 27 Jul 2002, Justin French wrote: > Date: Sat, 27 Jul 2002 11:35:23 +1000 > From: Justin French <justin@indent.com.au> > To: Michael <mlee@ni-solutions.com>, php-general@lists.php.net > Subject: Re: [PHP] calling user-defined php functions from <a href> tag > > 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 > > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, visit: http://www.php.net/unsub.php > >

« previous php.general (#109911) next »