0

I have php comment system like Facebook where user can post comment and reply. when I make 2 reply in a comment one after one then I cannot make 3rd reply in same comment. Also here cannot work emoticons slide and upload toggle. But can reply others comments. I cannot understand this type of jQuery behaviour!!! I also can't understand, can php create this type of problem?

For emoticons display yet I create review window behind textarea And make my textarea transparent. So here I used jQuery bind(). All comment and reply submit by AJAX.

When i going to reply 3rd time Its not work in same comment. But after refresh its work for more 2 reply only.

enter image description here

Here is some related jQuery:

$('.maintbox').on('keyup',function() {
    $(this).css('height','auto');
    $(this).css('height',Math.max(this.scrollHeight)+'px');
});
$('.replycom').livequery("click",function() {
    var VID = $(this).attr('id').replace('replycom','');
    $("#parent_id").attr("value", VID);
    $("#replycom"+VID).bind("keyup", function() {
       $("#replycom"+VID).html($(this).val());
       $(".review"+VID).html(smilyMe($("#replycom"+VID).val()));
    });
    return false;
}); 
$('.showhide_emobox').livequery("click",function(){
    var EID = $(this).attr("id");
    $("#emobox"+EID).slideToggle();
});
$(".embtno").livequery("click",function(event){
    var emotiText = $(event.target).attr("alt");
    var EID = $(this).attr('id').replace('','');
    var prevMsg = $("#replycom"+EID).val();
    $("#replycom"+EID).val(prevMsg + emotiText);
    $(".review"+EID).html(smilyMe($("#replycom"+EID).val()));
    $('#emobox'+EID).fadeToggle();
});

my form:

echo'<div class="replyform"><ul>
<form action="" method="post" class="repfrm'.$rows['id'].'" id="prepfrm">
<fieldset id="cmntfs">
    <input type="hidden" name="username" id="author" value="'.$_SESSION['username'].'"/>
    <input type="hidden" name="url" id="url" value="" />
    <div class="maintbox">
       <div class="chat">
           <div class="review'.$rows['id'].'" id="review"></div>
       <textarea name="replycom" id="replycom'.$rows['id'].'" class="replycom" placeholder="Type your comment ..."></textarea>
       </div>       
           <div align="right"><img src="images/envlop.png" width="25" alt="" class="uploadReply" id="'.$rows['id'].'" style="padding:2px;cursor:pointer;" />
               <div class="em">
               <img src="images/smile.png" id="'.$rows['id'].'" class="showhide_emobox"/>
                  <div id="emobox'.$rows['id'].'" class="emobox">
                  <img src="smilies/smile.gif" alt=":)" class="embtno" id="'.$rows['id'].'" />
                  <img src="smilies/sad.gif" alt=":(" class="embtno" id="'.$rows['id'].'" />
                  <img src="smilies/biggrin.gif" alt=":-D" class="embtno" id="'.$rows['id'].'" />
                 </div>
              </div>
          </div>
    <input type="hidden" name="parent_id" id="parent_id" value="'.$rows['id'].'" />
    <input type="hidden" name="tutid" id="tutid" value="'.$tutid.'" />
    </form>
    // Image upload system here
   </div>
    <button type="submit" name="submit" value="" id="repl'.$rows['id'].'" class="replyfrm">Post Reply</button>
    </fieldset>
</ul></div>';
Shiladitya
  • 11,210
  • 15
  • 22
  • 33
koc
  • 845
  • 8
  • 22
  • 1
    I don't fully understand the problem your question is trying to convey, but it sounds like an event delegation issue: http://stackoverflow.com/questions/203198/event-binding-on-dynamically-created-elements – Rory McCrossan Feb 04 '15 at 15:55
  • When i going to reply 3rd time Its not work in same comment. But after refresh its work for more 2 reply but not 3rd. – koc Feb 04 '15 at 15:59
  • @RoryMcCrossan Its now working to change .bind as .live. Thank you so so much. – koc Feb 04 '15 at 16:18
  • No problem, glad to help. – Rory McCrossan Feb 04 '15 at 16:18

1 Answers1

0

You are using:

 $("#replycom"+VID)

There can be only one id of the same name. Your first reply gets unique id, your second reply gets duplicate, and your code stops to work.

Marek
  • 7,086
  • 1
  • 17
  • 30