first post, im using the cakephp framework with ajax to create a reply button. the problem is that when a user clicks the reply button more then once the textbox keeps loading. how can i make it toggle so that when a user clicks it for the second time it closes the reply text box. right now i can just disable the button with thiss.remove(); but id rather close the text box. my code is below . thanks
<script type="text/javascript">
jQuery('.reply-button').live('click', function() {
var a = jQuery(this).data('comment_id');
var b = jQuery(this).data('video_id');
var c = jQuery(this).data('comment_quote');
var d = jQuery(this).data('reply_name');
var e = jQuery(this).data('quote_body');
var f = jQuery(this).data('topic_name');
var thiss = jQuery(this);
jQuery.ajax({
type: "POST",
url: "<?= $this->Html->url(array('controller' => 'comments', 'action' => 'reply')); ?>",
data: { comment_id: a, video_id: b, comment_quote: c, reply_name: d , quote_body: e , topic_name: f },
success: function(html) {
thiss.parent().parent().parent().append(html);
}
});
});
If your textbox has an
idorclassattribute I’d use that to determine if it’s visible/hidden/already loaded and based on that hide/show/load it.For example say the textbox has an id of
replyyou can do:Edit: I also change your
var thiss = jQuery(this);tovar thiss = this;asthisis already a jQuery object so it doesn’t need to go throughjQuery(this)to turn it into one.