I am echoing comments from database and echo looks like this:
echo $status->comment.'
<textarea id="'.$status->id.'"></textarea>
';
Now i have this code:
<script type="text/javascript">
$(document).ready(function() {
$('#'+'<?php echo $status->id;?>').keypress(function(event) {
var key = (event.keyCode ? event.keyCode : event.which);
if (key == 13) {
var comment = $('#' + '<?php echo $status->id;?>').val();
var status = '<?php echo $status->id;?>';
$.ajax({
method: "POST",
url: "file.php",
data: {status: status, comment: comment},
success: function(status) {
}
});
};
});
});
</script>
And it is not working... But when i set id to some name like comment and put it everywhere like this:
<textarea id="comment"></textarea>
$('#comment').keypress(function(event) {
var comment = $('#comment').val();
It works but only for first row in database like if I have 3 posts and post ids are 12, 17, 33. And I am commenting on post with id 33 it saves values to post with id 12 only to that one... Any help?
UPDATE:
I am using foreach and for each post from database I am echoing this:
echo "<div id='spacer'></div><div id='statusess' style='background: rgba(255,255,255,0);'><div id='pader' style='background-color:".$statuscolor.";'><div id='statuses' style='background: rgba(255,255,255,0.5);'><div id='rod'><a href='d/".$page."?fromid=".$frid."&toid=".$status->fromid."&forid=".$status->id."'>$rord</a></div> <a href='profile.php?u=".$status->fromid."'> <img src='../juzer/".$status->fromid."/profile/".$status->profilepic."'width='30px' height='30px'> ".$status->fromname."</a><br />".$status->text."<br /><br /><a href='d/npostlikes.php?u=".$frid."&type=status&id=".$status->id."'><img src='d/likes/like.png' width='20px' height='20px'></a>".$count."<textarea id='comm1_".$status->id."' name='comm1' onkeyup='textAreaAdjust(this)' style=' resize: none; width: 300px; height: auto; '></textarea>";
The end of echo is my problem and the problem is that when I press key it saves to database only first post id from posts database. So basically i am trying to say that every comments it is storing as comments for only first post from posts database... So I want to add id to each textarea as unique so when ssomeone press key it saves to that id not first one only....