How can I get a value from many different textarea tags with same IDs using jQuery? I also need to allow the user a choice of which textarea he/she wants to add a comment, and then get the comment.
This is my HTML
<div class="container">
<div class="wall_post">
<p>First Post</p>
<textarea id="user_comment" class="form-control" placeholder="Type your comment here"></textarea>
</div>
<div class="wall_post">
<p>Second Post</p>
<textarea id="user_comment" class="form-control" placeholder="Type your comment here"></textarea>
</div>
<div class="wall_post">
<p>Third Post</p>
<textarea id="user_comment" class="form-control" placeholder="Type your comment here"></textarea>
</div>
<div class="wall_post">
<p>Fourth Post</p>
<textarea id="user_comment" class="form-control" placeholder="Type your comment here" ></textarea>
</div>
</div>
And this is my jQuery so far
This jQuery only prints out the first textarea value, but is ignoring the others.
$(document).on('keydown', function(e) {
var targetInput = $('#user_comment');
if(!targetInput.is(document.activeElement)) {
alert('Typed while not focused on #myInput!');
}else{
if(e.which == 13){
alert(targetInput.val());
targetInput.val('');
}
}
});
Thank you in advance!