onclick execute php function

Posted on 2011-10-29
Last Modified: 2012-05-12
hi all,

I know how to run some javascript when I click on a link using onclick="runthis();" ... my question is ... how can I do this and run a php function instead?

Question by:error77
    LVL 81

    Accepted Solution

    LVL 30

    Expert Comment

    by:Marco Gasi
    I'm sorry, but you can't. Php is a server-side language not a client side one as Javascript is, so you can't simply run a php function clicking a button.
     Maybe you can tell what does that function and I could find a solution to use it - maybe... :-)



    Author Comment

    I didn't want to use ajax. I just wanted to run some php code when I click the onclick event link but don't need a return ... I would just add an alert saying "Done!" or something link that.

    I actually need something simpler than that.

    LVL 25

    Expert Comment

    by:Lee Savidge
    You can't directly. You need to post back to the server and call the function serverside. PHP is a server side language and javascript is typically a client side language. The client side script interacts with the page and the clientside DOM only. It doesn't interact with anything server side.


    Author Comment

    I see why leakim971 was using Ajax then....hmm

    Featured Post

    6 Surprising Benefits of Threat Intelligence

    All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

    Join & Write a Comment

    This article describes how to create custom column layout styles for Bootstrap. The article uses 5 columns to illustrate the concept, but the principle can be extended to any number of columns.
    Not sure what the best email signature size is? Are you worried about email signature image size? Follow this best practice guide.
    In this tutorial viewers will learn how to embed videos in a webpage using HTML5. Ensure your DOCTYPE declaration is set to HTML5: "<!DOCTYPE html>": Use the <video> tag to insert a video. Define the src as the URL of your video; this is similar to …
    The viewer will learn how to dynamically set the form action using jQuery.

    734 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    19 Experts available now in Live!

    Get 1:1 Help Now