April 25th, 2000, 05:44 PM
-
lo all,
well, i was wondering - is there a way to get a function to go when you click on a link? or can you only make that kind of thing work with forms?
April 26th, 2000, 01:19 AM
-
you may pass one variable value with link.
eg:
<a href="test.php3?variable_val=1">test</a>
In test.php3 just check the variable value and call the function.
<?php3
if($variable_val==1){
#call your function here...
}
?>
------------------
SR -
shiju.dreamcenter.net
April 26th, 2000, 08:03 AM
-
actually, i wanted to keep it on the same page with something like
<?
function foo() {
}
<A href="foo()">foo</a>
but i dont think that works
April 26th, 2000, 08:18 AM
-
I think to do what your trying all you have to do is
---
<?
function foo()
{ ... }
?>
<a href="<? foo(); ?>">foo</a>
---
maybe i'm wrong here, you could also just have foo() print out <a href="link"> if the "'s are causing the problem.
-Justin
April 26th, 2000, 10:34 AM
-
No, you can't do that. PHP is a SERVER SIDE language. Once the code is sent to the client it is no longer available to execute. You can't execute server side code of any kind from the browser without some sort of request to the server.
April 26th, 2000, 10:40 AM
-
he's not talking javascript though rod. It'd still be server side
-Justin
April 26th, 2000, 03:08 PM
-
WHAT? We're talking about calling a function with a link. The link has to be on the client side for it to work. And you can't call a server side function that's in the same script as the link itself.
Again, Trauma, you can't execute server side code from the browser without a page request from the client. You can't execute just a function, and you can't execute code that's already been parsed (which it has if it's on the client window.)
April 27th, 2000, 03:54 PM
-
in that case, is it possible to get javascripting to execute any PHP coding?
April 27th, 2000, 06:13 PM
-
No, this is still not possible. Javascript is client side, PHP is server side. The client doesn't get the finished page (with the javascript code in it) until the PHP is done executing. Once that has happened, the only way to get more PHP to run is to load a new page.
Depending on what you are trying to accomplish, you may be able to get an appropriate result by passing variables as Shiju Rajan mentioned. Just create a new page with the function you want to run, create a link to that page passing it the variables it needs to function, and then when the user clicks on the link your function will run. Of course, if you want to run the function without leaving the page you are currently on you may be out of luck...
Hope that helps!
--David
April 27th, 2000, 11:06 PM
-
You need to set up a switch statement, maybe call it "action"... and then set the action value equal to what function you want...
I.E.
<?
//functions here
switch action{
case output: print_output();
case input: print_input();
}
?>
<html>
etc etc
<a href="<?php echo $PHP_SELF?action=output ?>">Print output</a>
</html>
My syntax is wayyy off, but that's the general idea. HTH