How to call the function from javascript

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • rafi83
    New Member
    • Jun 2007
    • 1

    How to call the function from javascript

    hi
    i want to access the php function from the javascript

    this is code

    [code=php]
    <html>
    <body bgcolor="#FFFFF F">
    <title>CodeAve. com(JavaScript: Confirm Alert Box)</title>

    <script language="JavaS cript">

    function confirm_entry()
    {
    input_box=confi rm("Click OK or Cancel to Continue");
    if (input_box==tru e)
    {
    // i want call the php function here........... ............//
    // Output when OK is clicked
    alert ("You clicked OK");
    }

    else
    {
    // Output when Cancel is clicked
    alert ("You clicked cancel");
    }
    }
    </script>
    Click <a href="JavaScrip t:confirm_entry ()">here</a>
    <p>
    <form onSubmit="confi rm_entry()">
    <input type="submit" >
    </form>
    </body>
    </html>

    //php function here
    [/code]


    Advance Thank
    Last edited by Atli; Jun 18 '07, 10:56 AM. Reason: Added code tags
  • Atli
    Recognized Expert Expert
    • Nov 2006
    • 5062

    #2
    Hi rafi83, and welcome to TSDN.

    Calling PHP functions directly from JavaScript is not possible.

    This is because PHP code is executed on the server, before the HTML is sent to the browser.
    Javascript on the other hand is executed by the browser once the HTML has reached the client.

    Comment

    • pbmods
      Recognized Expert Expert
      • Apr 2007
      • 5821

      #3
      Heya, rafi83.

      To add to Atli's post, you can use JavaScript to create an AJAX call that loads a script to call the function.

      Comment

      • safnate
        New Member
        • Oct 2007
        • 3

        #4
        Originally posted by rafi83
        hi
        i want to access the php function from the javascript

        this is code

        [code=php]
        <html>
        <body bgcolor="#FFFFF F">
        <title>CodeAve. com(JavaScript: Confirm Alert Box)</title>

        <script language="JavaS cript">

        function confirm_entry()
        {
        input_box=confi rm("Click OK or Cancel to Continue");
        if (input_box==tru e)
        {
        // i want call the php function here........... ............//
        // Output when OK is clicked
        alert ("You clicked OK");
        }

        else
        {
        // Output when Cancel is clicked
        alert ("You clicked cancel");
        }
        }
        </script>
        Click <a href="JavaScrip t:confirm_entry ()">here</a>
        <p>
        <form onSubmit="confi rm_entry()">
        <input type="submit" >
        </form>
        </body>
        </html>

        //php function here
        [/code]


        Advance Thank
        Calling PHP functions directly from JavaScript is not possible.

        This is because PHP code is executed on the server, before the HTML is sent to the browser.
        Javascript on the other hand is executed by the browser once the HTML has reached the client.

        u can only call ur .JS function by saying:$btnname->setOnclick("re turn validDelete()") ; this will only show the dialog and will also delete even if u press Cancel. u wil have to use Ajax for this.

        Comment

        Working...