Again I'm asking question about comment form, I'm making an image website and every image has its own comment form, so when I submit form I do like this :
$('#comment_form').live('submit', function() {
...
So in order to select only this form textearea value I tried using this but I get undefined error here is how I tried :
$('#comment_form').live('submit', function() {
image_comment_text=$(this).closest("#comment_text").val(); //textarea id is comment_text
I tried to used find(), its working but when I submit comments for few images I get comments 2 or 3 times as I should, because find finds all occurrences of textarea with comment_text id .. how can I do this ?
@molf , here is HTML generated by javascript:
var xHTML = "<div class=\"addComment\">";
xHTML += "<form action=\"<?=base_url()?>images/post_comment/" + post + "\" method=\"post\" class=\"comment_form\" name=\"comment_form\">";
xHTML += "<input type=\"hidden\" class=\"comment_post_id\" name=\"comment_post_id\" value=\"" +post + "\"/>";
xHTML += "<textarea class=\"comment\" name=\"comment_text\" rows=\"8\" cols=\"40\"></textarea>";
xHTML += "<input type=\"submit\" name=\"submit\" class=\"post_image_comment\" value=\"Comment\"><span> Don't make it too big!</span>";
xHTML += "</form></div>";
EDIT
When I print to console log the value of textarea I get only one result as I should, now when I try to append the ul comments I get 2 of the same values .. here how it goes ..
<ul class="comments"></ul>
below is the comment form which is not in the document at all, when certain anchor is clicked the form pops out below .comments
, when form submits I want to append the comments to add the new comment to list items of existing unordered list comments , here is the whole code :
$('form[name^="comment_form"]').live('submit', function(event) {
r= $(this).find('> .comment').val();
$('<div class="overlay"></div>')
.appendTo('.addComment')
.fadeIn(200, function() {
$('.comments')
.append('<li id="new_append">' + r + '</li>')
.children(':last')
.height($('.comments li:last').height())
.hide()
.slideDown(800, function() {
var bodyHeight = $('html').height();
$('.addComment').fadeOut(500, function() {
$('html').height(bodyHeight);
$('h2#leaveAComment').fadeOut(200, function(){$(this).text('Thank you for your comment!').fadeIn(200)});
});
});
$('html, body').scrollTo( $('#new_append'), 800 );
});
event.preventDefault();
});
EDIT II @patrick
The javascript which loads the comment form is above .. here is HTML :
-------------BEGIN FOR EACH--------------
<div id="image-12" class="image_content">
<img src="..." />
<ul class="comments hidden"> //This is where the comments are appended to <li></li>
</ul>
<div style="float: left; display: block; width: 100%;">
<a id="image_comment-12" class="image_comment" onclick="showComments('12');" href="javascript:;">Add Comment</a>
</div>
<div id="addComment-12">//this is where the comment form loads
</div>
</div>
----------END--- FOR EACH--------- image ...