title: Calling a jQuery function from a PHP file
body: <p>I am having problems trying to activate a jQuery function from a PHP.</p>
  
  <p>The following is my own test version. </p>
  
  <h2>index.php file</h2>
  
  <pre><code>    &lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"           "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&gt;
      &lt;html xmlns="http://www.w3.org/1999/xhtml"&gt;
  
  &lt;head&gt;
  
      &lt;meta http-equiv="Content-Type" content="text/html; charset=utf-8" /&gt;
  
      &lt;title&gt;Welcome to temp index&lt;/title&gt;
  
      &lt;link rel="stylesheet" href="style.css" type="text/css" /&gt;
      &lt;script type="text/javascript" src="scripts/jquery-1.8.3.min[2].js"&gt;&lt;/script&gt;
      &lt;script type="text/javascript"&gt;
  
          $(document).ready(function() {
  
              //posts info into the userinfo.php file
              $.post('userinfo.php', { activate:"colourchange"}, function(data){
                  $('report').html(data);
              });
  
              //the function which is meant to be activated from the php file
              function colourchange(){
                  document.body.style.backgroundColor = 'green';   
               };         
  
           }); 
  
      &lt;/script&gt;
  
  &lt;/head&gt;
  
  &lt;body&gt;
    &lt;h1&gt;hello&lt;/h1&gt;
  
  &lt;div id="report"&gt;
  &lt;/div&gt;
  
  &lt;/body&gt;
  
  &lt;/html&gt;
  </code></pre>
  
  <h2>PHP file I am attempting to call my jQuery function from</h2>
  
  <pre><code>&lt;?php
  
  if( $_REQUEST["activate"])
  {
    $activate = $_REQUEST['activate'];
  };  
  
  if($activate == 'colourchange') 
  {
   // This is the code that I believe not to be working as this isn't 
   // activating the jQuery function to work. (The page background isn't changing colour)
  
      echo "&lt;script&gt;colourchange(); &lt;/script&gt;"; 
  };
  
  ?&gt;
  </code></pre>
  
  <p>Thank you to anyone who has an idea of what to do it is much appreciated. </p>
  
  <p>I have now tried ... </p>
  
  <pre><code>&lt;?php
  require 'userinfo.php';
  ?&gt;
  &lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&gt;
  &lt;html xmlns="http://www.w3.org/1999/xhtml"&gt;
  
  &lt;head&gt;
  
  &lt;meta http-equiv="Content-Type" content="text/html; charset=utf-8" /&gt;
  
  &lt;title&gt;Welcome to temp index&lt;/title&gt;
  
  &lt;link rel="stylesheet" href="style.css" type="text/css" /&gt;
  &lt;script type="text/javascript" src="scripts/jquery-1.8.3.min[2].js"&gt;&lt;/script&gt;
  &lt;script type="text/javascript"&gt;
  
   function colourchange(){
      document.body.style.backgroundColor = 'green';   
    };
  
  
  
    $(document).ready(function() {
      $.post('userinfo.php', { activate:"colourchange"}, function(data){
        $('report').html(data);
      });    
   }); 
  
  
  &lt;/script&gt;
  
  &lt;/head&gt;
  
  &lt;body&gt;
    &lt;h1&gt;hello&lt;/h1&gt;
  
  &lt;div id="report"&gt;
    &lt;/div&gt;
  
  
  
  &lt;/body&gt;
  
  &lt;/html&gt;
  </code></pre>
  
  <p>and the PHP index file is ...</p>
  
  <pre><code>&lt;?php
  
  
  if( $_REQUEST["activate"])
  {
  
    $activate = $_REQUEST['activate'];
  
  };  
  
  
  
  
    if($activate=='colourchange')
    { 
      echo "colourchange();";
    };
  
  ?&gt;
  </code></pre>