Here is my code:
$(".cbtn").click(function(e) {
alert("here");
var id = $(this).attr('id');
var comment = $('input[id$=id]').val();
alert("hay" + id);
alert(comment);
$.post("comments.php", {
id: id,
comment: comment
})
});
});
The id
of cbtn
and the text field is created dynamically like this:
<input type="text" class="enter_comment value="comments" id="comm<?php echo $row['p_id'];?>"/>
<input type="button" value="enter" class="cbtn" id="<?php echo $row['p_id'];>">
When cbtn
is clicked, I want to get the id
of text field that ends with the same id as cbtn
. But it is returning undefined
instead.