Possible Duplicate:
Pass a PHP string to a Javascript variable (and escape newlines)
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.
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.
This is the PHP and HTML. The function runs when submit is clicked.
$comment = "7b";
echo"
<table>
<p><input type='text' id='newPostComment' value='' placeholder='WRITE YOUR COMMENT HERE...' size='35'/><input type='submit' value='UPLOAD' onclick='uploadPostComment($parentID, $comment);fetchComment()'/></p>
</table>
This is the javascript function.
function uploadPostComment(PostCID, Comment){
var PostCommentData = "fsPostID="+PostCID;
PostCommentData += "&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);}