title: How do I pass a PHP string into a Javascript function call?
body: <blockquote>
    <p><strong>Possible Duplicate:</strong><br>
    <a href="https://stackoverflow.com/questions/168214/pass-a-php-string-to-a-javascript-variable-and-escape-newlines">Pass a PHP string to a Javascript variable (and escape newlines)</a>  </p>
  </blockquote>
  
  
  
  <p>So, essentially I am trying to pass a string from a PHP page as an argument for a javascript function. The PHP is included in the page that the script is on, but they are in two separate files.</p>
  
  <p>However, whenever I try to pass a string, it stops the javascript from running. I can pass PHP integers, but not strings. Is it possible to fix this? I've been looking around the internet for what might be causing my error, but I can't find anything. Any help would be greatly appreciated.</p>
  
  <h2>This is the PHP and HTML. The function runs when submit is clicked.</h2>
  
  <pre><code>$comment = "7b";
  echo"
      &lt;table&gt;
           &lt;p&gt;&lt;input type='text' id='newPostComment' value='' placeholder='WRITE YOUR COMMENT HERE...' size='35'/&gt;&lt;input type='submit' value='UPLOAD' onclick='uploadPostComment($parentID, $comment);fetchComment()'/&gt;&lt;/p&gt;
      &lt;/table&gt;
  </code></pre>
  
  <h2>This is the javascript function.</h2>
  
  <pre><code>function uploadPostComment(PostCID, Comment){
  
        var PostCommentData = "fsPostID="+PostCID;
        PostCommentData += "&amp;fsPostComment="+Comment;
  
        var xmlHttp = new XMLHttpRequest();
        xmlHttp.open("post", "uploadPostComment.php", true);
  
        xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
        xmlHttp.setRequestHeader("Content-length", PostCommentData.length);
        xmlHttp.setRequestHeader("Connection", "close");
  
        xmlHttp.onreadystatechange = function()
           {
               if(xmlHttp.readyState == 4)
               {
                  if(xmlHttp.status == 200)
                  {
                      alert("Message Posted");
                  }
                  else
                  {
                      alert("Oh no, an error occured2"); 
                  }
               }
           };
           xmlHttp.send(PostCommentData);}
  </code></pre>