Reputation: 1579
Im experiencing a problem where the click event assigned to the button tag is not firing upon clicking. There are several buttons with same class attribute but this should not effect the JS since class selector effects all matched elements.
The entire html part is hidding on page load and shown properly when a specific link is clicked, but no event is fired when clicking the submit button. Also would someone be kind and link the url for jquery, bootstrap.css and bootstrap.js if you have it close by so I can try to create the desired effect in jsfiddle. Much obliged
HTML:
<span class="reply-comment" id="<?php echo $imagecomments[1][$i]['commentid']; ?>">
<div class="row-fluid">
<div class="span11 offset1">
<textarea class="<?php echo $imagecomments[1][$i]['commentid']; ?>" id="reply-textarea"></textarea><br>
<button class="btn btn-mini submit-reply-button" data-commentid="<?php echo $imagecomments[1][$i]['commentid']; ?>"><strong>Submit</strong></button>
</div>
</div>
JS:
$('.reply-comment').hide();
$('.submit-reply-button').click(function(e){
e.preventDefault();
var commentid = $(this).data('commentid');
var reply = $(textarea.commentid).val();
var filename = $('.mainimage').data('filename');
var imgowner = $('.mainimage').data('imgowner');
$.ajax({
type: 'POST',
url: '?category=addimgcomment',
data: {
"commentid" : commentid,
"imgcomment" : reply,
"filename" : filename,
"imgowner" : imgowner
},
success: function(data){
$(textarea.commentid).val("");
$('.'+commentid+'subcomments').html(data);
}
});
return false;
});
Upvotes: 0
Views: 132
Reputation: 207501
What do you think $(textarea.commentid)
is doing?
Look at the console, I am betting there is an error. It is looking for a variable named textarea with a property of commentid. That is not what you are after.
What you want is to build the selector string
$("textarea." + commentid).val()
Upvotes: 2