#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2000
    Posts
    38
    Rep Power
    15
    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?
  2. #2
  3. .Net Developer
    Devshed Novice (500 - 999 posts)

    Join Date
    Feb 2000
    Location
    London
    Posts
    987
    Rep Power
    15
    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
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2000
    Posts
    38
    Rep Power
    15
    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
  6. #4
  7. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2000
    Posts
    33
    Rep Power
    15
    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
  8. #5
  9. No Profile Picture
    Apprentice Deity
    Devshed Loyal (3000 - 3499 posts)

    Join Date
    Jul 1999
    Location
    Niagara Falls (On the wrong side of the gorge)
    Posts
    3,237
    Rep Power
    19
    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.
  10. #6
  11. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2000
    Posts
    33
    Rep Power
    15
    he's not talking javascript though rod. It'd still be server side

    -Justin
  12. #7
  13. No Profile Picture
    Apprentice Deity
    Devshed Loyal (3000 - 3499 posts)

    Join Date
    Jul 1999
    Location
    Niagara Falls (On the wrong side of the gorge)
    Posts
    3,237
    Rep Power
    19
    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.)
  14. #8
  15. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2000
    Posts
    38
    Rep Power
    15
    in that case, is it possible to get javascripting to execute any PHP coding?
  16. #9
  17. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2000
    Posts
    1
    Rep Power
    0
    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

  18. #10
  19. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2000
    Posts
    26
    Rep Power
    0
    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

Similar Threads

  1. Uploading Files
    By vivekjain in forum ASP Programming
    Replies: 0
    Last Post: February 17th, 2004, 12:21 AM
  2. database access using thread
    By padmini in forum Visual Basic Programming
    Replies: 3
    Last Post: February 6th, 2004, 01:38 AM
  3. send in an href to a javacript function
    By Devboy in forum HTML Programming
    Replies: 1
    Last Post: February 5th, 2004, 04:56 AM
  4. send in an href to a javacript function
    By Devboy in forum HTML Programming
    Replies: 0
    Last Post: February 5th, 2004, 12:32 AM
  5. Code Benchmarking Tests
    By infamous41md in forum C Programming
    Replies: 4
    Last Post: December 27th, 2003, 05:15 PM

IMN logo majestic logo threadwatch logo seochat tools logo