Is there a way to integrate php code inside javascript function :

ex :
<script language=javascript>
function func(){
<?
//phpcode
?>
}
</script>

I tried this but the php code runs immediatly when the page loads , independent of the javascript function :rolleyes:

    Of course it does.
    PhP is a server-side language. this means the code is executed, BEFORE the page is oaded in the webbrowser. Javascript runs on the CLIENTS computer.

    So.. No you cannot combine them in this way.

    You could of course have javascript load a new page and/or refresh your page to perform some PhP action in an other page.
    But I would not rely on this.

    J.

      have the PHP create the out putted javascript. The 2 can never interact in anyway whatsoever withe ach other directly, but one can help the other.

      Say you have a javascript thumbnail gallery. PHP can pull all the info about all the images and then output it in javascript form. You basically put the javascript commands around the PHP echo commands. get me?

        Yeah - you must do a server call to run any new php code.

        However, you can have a javascript function that runs a php page and returns the results to your page, without refreshing the whole page - if thats whats required ?

          You can? Im not terribly storng on Javascriot and would just like to ask how you would do that?

            Originally posted by RossC0
            Yeah - you must do a server call to run any new php code.

            However, you can have a javascript function that runs a php page and returns the results to your page, without refreshing the whole page - if thats whats required ?

            how can i call php page without refreshing ? or without opening the new page ?

              Hi,

              Using the XMLHTTPRequest feature of modern browsers allows you to speak to the server without reloading the whole page and get information back from the server and display it on page through the DOM.

              Checkout these:

              JSPAN - PHP & Javascript Class
              Autocomplete Comes of Age (for ideas)

              I use it as an autocomplete for a search and to retrieve snippets of information fired by onhover events when a user looks at particular data in a report.

                Write a Reply...