1st answer: You need to hide form before show reply form;
$('body').on('click','.btn_reply',function(){
// Hide previous form
$(".quickReplyForm").remove();
var id = $(this).data('id'); //get the `id` from data property
var name = $(this).data('name');
$("#comment_id").val(id);
//alert(id + "/" + name);
$(this).after('<div class="quickReplyForm">'+$(".reply_form").html()+'</div>');
});
And another importan point, you need to update id
and name
field of reply form on each opened form. Or else, you save comment on wrong comment
2nd answer: In your second case you need to use delegate structure;
$('body').on('click','#btn_reply_comment',function(){
var parameters = $(this).closest('#reply_form').serialize();
alert(parameters);
// ajax here
});
Here is a working demo for 2nd answer: jsfiddle
Edit:
In order to add id to comment form,
You can do that by adding a hidden form to .reply_form
like;
<div class="row reply_form" style="display:none;">
<div class="col-md-6">
<form role="form" id="reply_form">
<div class="form-group">
<input type="text" class="form-control input-sm" name="message">
</div>
<input type="hidden" id="comment_id" value=""/>
<button type="button" class="btn btn-success" id="btn_reply_comment">Reply Comment</button>
</form>
</div>
</div>
And then, before opening form you can call;
$("#comment_id").val(id);