title: Write javascript code in PHP
body: <p>My index.php</p>
  
  <pre><code>    switch ($action){
  
           case "calendar":
  
           echo "&lt;script language=\"javascript\"&gt;\n";
  
           echo "document.write('Hello World!')";
  
           echo "&lt;/script&gt;";
  
           include($_STR_TEMPLATEPATH."/calendar_view.php");
  
           break;
  
      }
  </code></pre>
  
  <p>my calendar_view.php:</p>
  
  <p>I have an ajax function which should call the <code>action</code> <code>calendar</code> from the <code>index</code> and display the result on <code>calendar_view.php</code> in <code>calendar div</code></p>
  
  <pre><code>&lt;script&gt;
      function calendarList()
      {
      var xmlHttp;
      try
        {
        // Firefox, Opera 8.0+, Safari
        xmlHttp=new XMLHttpRequest();
        }
      catch (e)
        {
        // Internet Explorer
        try
          {
          xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
          }
        catch (e)
          {
          try
            {
            xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
            }
          catch (e)
            {
            alert("Your browser does not support AJAX!");
            return false;
            }
          }
        }
      xmlHttp.onreadystatechange=function()
      {
      if (xmlHttp.readyState==4 &amp;&amp; xmlHttp.status==200)
        {
        document.getElementById("calendar").innerHTML=xmlHttp.responseText;
        }
      }
  
        xmlHttp.open("GET","?action=calendar",true);
  
        xmlHttp.send(null);
  
      }
    &lt;/scritp&gt;
  </code></pre>
  
  <p>The calendar div:</p>
  
  <pre><code>&lt;div id="calendar"&gt;&lt;/div&gt;
  </code></pre>
  
  <p>When I call the <code>calendarList function</code> it did call the case, but did not display the result in <code>calendar div</code>. </p>
  
  <p>Any help. Thanks</p>