Let me know where I'm wrong. I've been trying to send php variable within a onclick function argument but its not working. The argument is passed in InsertReply function. Here is the code:
$sql22 = "SELECT * FROM comments WHERE PostID=$id";
$count22=$conect->query($sql22);
if($count22->num_rows>0){ //If comments exist
while($row = $count22->fetch_array()){ //Fetching Comments
$mail = $row['UserMail'];
$comment = $row['Comment'];
$comment_id = $row['ID'];
echo "<br>";
echo "<p>".$comment_id."</p>";
// Reply input field starts
?>
<input type='text' name='reply' id='reply' placeholder='Enter Reply here' min='5' max='100' class='big-input' style='width:40%;margin-left:40px;margin-right:40px;'>
<?php
echo "<input type='hidden' name='mail' id='mail' value= '".$current_user."'/>";
echo "<input type='hidden' name='postid' id='postid' value= '".$id."'/>";
echo "<button class='btn btn-outline-info' onclick='InsertReply(<?php echo $comment_id ?>)'>Reply</button>";
}
}
Here is the InsertReply Function:
function InsertReply(x) {
alert("Insert Reply Function Called! with comment id : " + x);
//Storing values in variables
var reply = document.getElementById("reply").value;
var mail = document.getElementById("mail").value;
var p_id = document.getElementById("postid").value;
alert("Reply is "+reply);
alert("Reply will be added with Reply : " + reply + ", by : "+ mail + ", Post ID : " + p_id + " & Comment ID : "+x);
I know there are lots of issues with the code. Please guide me as I'm badly stuck. Let me know if anything else is required. I just want to send variable value to the InsertReply function. Any alternate method or suggestion will be highly appreciated.