Find the answer to your Linux question:
Results 1 to 2 of 2
Hi every body, I'm very new to php ,please help me with this problem: In a *.php file i have some html , java script and php code like: <script> ...
  1. #1
    Just Joined!
    Join Date
    Aug 2008
    Posts
    10

    How use php that not execute at page load?

    Hi every body,
    I'm very new to php ,please help me with this problem:
    In a *.php file i have some html , java script and php code like:

    <script>
    function confirmapply()
    {
    var ans= confirm("are you sure?");

    if (ans)
    {
    <?php
    //some php code
    ?>
    }

    }
    </script>

    <html>
    <body>
    <input type = "button" value= "apply" onclick="confirmapply();">
    </body>
    </html>

    my problem is that when the page loads, the php code at javascript function will execute (because it is server side) .but I want that it execute just when apply button is clicked. Now what should I do?


    thanks a lot.

  2. #2
    Linux Engineer GNU-Fan's Avatar
    Join Date
    Mar 2008
    Posts
    935
    You can't.
    PHP is processed on the server, Javascript on the client -- meaning that the browser never sees any PHP code, only the result of it.

    Depending on what that "some php code" does, you could either rewrite it entirely in Javascript or you point to another PHP page when the button has been clicked. This new PHP page takes the value of the button as an argument and delivers an output depending on this value.
    Debian GNU/Linux -- You know you want it.

Posting Permissions

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