SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Zealot
    Join Date
    Aug 2004
    Location
    Australia
    Posts
    122
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    How to call a PHP Function from clicking a button?

    I want to run a function in php when a user clicks a button

    I was doing <input type.........onClick='function()'> but when iclick it i get a javascript error :|

    So, how can i call a PHP function from clicking a button?

  2. #2
    SitePoint Addict
    Join Date
    Jan 2004
    Location
    Colorado Springs
    Posts
    308
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You can't call a PHP function from within the cached page. Have the button pop up in a new window and perform your function before the new page loads.

    PHP always parses before a page is returned, therefore, you can't work functions dynamically like you can in JavaScript. Hence, calling function() with onClick'' returns a javascript error.

  3. #3
    SitePoint Zealot
    Join Date
    Aug 2004
    Location
    Australia
    Posts
    122
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Maybe i could have the page refresh with index.php?funtion=yes

    if ($_GET['function'] == yes)
    {
    function foo()
    {}
    }

    Something that might work wont it?

  4. #4
    SitePoint Addict
    Join Date
    Aug 2004
    Location
    California
    Posts
    267
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Cheeky Chino
    I want to run a function in php when a user clicks a button

    I was doing <input type.........onClick='function()'> but when iclick it i get a javascript error :|

    So, how can i call a PHP function from clicking a button?
    You'd have to have the button target a new page, or reload the old one. Then you should be able to perform the function server-side without a problem.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •