Because you are multiple elements with the id comment_form
.. id of an element must eb unique.. so use a class name comment
for the form to add the submit handler like
$('form.comment').submit(function () {
event.preventDefault();
var $form = $(this);
$.ajax({
beforeSend: function () {
$('#show-results').html('Processing...');
},
url: 'inc/process-form',
type: 'POST',
data: ({
comment: $form.find('input[name="comment"]').val(),
pid: $form.find('input[name="pid"]').val(),
date_comment: $form.find('input[name="date_comment"]').val()
}),
success: function (results) {
$('.show-results').html(results).slideToggle().delay(2000).slideToggle();
$form[0].reset();
}
});
return false;
});
When you use id selector, it will return only the first element with the given id, so when you use $('#comment_form')
it returns only the first form element, thus your submit handler get registered to only the first comment form