I want to have a comment form for each image on a page. The number of images are dynamic. Is there a way for jquery to target the form data for the submit button that was clicked?
I currently have:
$('.comment_button').click(function() {
var comment = $('input#comment').val();
var id = $('input#id').val();
var other = $('input#other').val();
var dataString = 'comment='+ comment + '&id=' + id + '&other=' + other;
alert (dataString);
});
Which means all the form fields and form names are the same for each image (probably should make them unique for validation) but regardless is there a way to get the form fields for when a user clicked a certain submit button in that particular form?
As your problem I understand,
You can use
serializefunction for thatlike
});
Documentation here JquerySerialize