Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7164513
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T14:05:15+00:00 2026-05-28T14:05:15+00:00

I have this really weird bug at my page. I wrote this comment system

  • 0

I have this really weird bug at my page. I wrote this comment system that when you add a comment it adds the new comment with a nice animation (unhides it by animating the height). Not the problem is, when you add a long comment (close to the max characters allowed) and after that add another one, the last animation stops when the height is 1px and all other animations on the page (like hovers) stop working as well. I have no idea what is causing this.

Here’s the link to my page http://ttrcustoms.us/testarea51/#track=1323924558

function addComment(el, evenorodd, user, avatar, comments){
numberofcomments = parseInt(comments);
newnumberofcomments = numberofcomments;
realnumberofcomments = numberofcomments + 1;
numberofcomments--;
theLastID = "#commentborder" + numberofcomments;
deleteLast = "#delete" + numberofcomments;
fadeLast = "#fade" + numberofcomments;
theCommentID = "#thecomment" + newnumberofcomments;
newcomment = "#fade" + newnumberofcomments;
commentID = "#comment" + newnumberofcomments;
commentBorderID = "#commentborder" + newnumberofcomments;

if (window.XMLHttpRequest){
    // code for IE7+, Firefox, Chrome, Opera, Safari
    xmlhttp=new XMLHttpRequest();
}else{
    // code for IE6, IE5
    xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}

//Fade textarea
$("#enter-comment").attr("readonly", true).fadeTo(500, 0.5);

xmlhttp.onreadystatechange=function(){
    if (xmlhttp.readyState==4 && xmlhttp.status==200){
        //Add the comment from the DB
        document.getElementById("serverResponse").innerHTML=xmlhttp.responseText;

        if(xmlhttp.responseText != "success"){
            //Show error if there is one
            jQuery.fn.center = function (widthmodification, heightmodification) {
                this.css("position","fixed");
                this.css("top", (($(window).height() - this.outerHeight()) / 2) + $(window).scrollTop() + heightmodification + "px");
                this.css("left", (($(window).width() - this.outerWidth()) / 2) + $(window).scrollLeft() + widthmodification + "px");
                return this;
            }
            $("#serverResponse").center(-32, -75);
            $("#pageoverlay").fadeTo(500, 0.75);
            $("#serverResponse").fadeIn(500);

            $("#pageoverlay").click(function() {
              $("#serverResponse").fadeOut(500);
              $("#pageoverlay").fadeOut(500);
              $(deleteimg).html("✖");
              $("#enter-comment").fadeTo(500, 1);
            });
        }else{
            //Show the comment
            $(fadeLast).after("\n<span id='fade"+newnumberofcomments+"' class='fadecomment' onmouseover='$(\"#delete"+newnumberofcomments+"\").fadeTo(200,1);' onmouseout='deleteOut(event, \""+newnumberofcomments+"\")' style='display: none; width: 679px;'>\n<span class='comment' id='comment"+newnumberofcomments+"'>\n<span class='"+evenorodd+" bottom-comment' id='commentborder"+newnumberofcomments+"'>\n<div class='avatarWrapper' id='avatarwrap"+newnumberofcomments+"'><img src='images/avatars/"+avatar+"' class='avatar32' id='avatar"+newnumberofcomments+"'/></div>\n<span class='thecomment' id='thecomment"+newnumberofcomments+"'>\n<a href='#' class='userl' id='userl"+newnumberofcomments+"'>"+user+"</a>&nbsp;"+el.elements['enter-comment'].value+"</span>\n</span>\n<span class='delete-holder' id='delete-holder"+newnumberofcomments+"'>\n<span class='delete-comment' style='opacity: 0;' id='delete"+newnumberofcomments+"' lang='bottom' onclick='removecomment(0,\"1\",this.lang,\"even\",document.getElementById(\"nrofcomments\").innerHTML);'>&#x2716;</span>\n</span>\n</span>\n</span>\n");
            $(newcomment).css({visibility:"visible",display:"block",position:"absolute"});
            theHeight = $(theCommentID).height() + 2;
            if(theHeight < 36){
                theHeight = 36;
            }
            $(newcomment).css({display:"none",position:"relative",visibility:"visible"});
            $(commentID).height(theHeight);
            $(commentBorderID).height(theHeight);
            $(newcomment).height(theHeight);
            $(newcomment).animate({height: 'show'},500);
            $("html, body").animate({ scrollTop: $(document).height() }, 500);

            //Flat out corners of last comment
            $(theLastID).removeClass("bottom-comment").addClass("middle-comment");
            $(deleteLast).attr("lang", "middle");

            //Reset texarea
            $("#enter-comment").fadeTo(500, 1).removeAttr("readonly").val("Write a comment...").css("color","#ccc");

            //Change the current number of comments and if the next one needs to be even or odd
            $("#nrofcomments").html(realnumberofcomments);
            if(evenorodd == "even"){
                $("#newevenorodd").html("odd");
            }else{
                $("#newevenorodd").html("even");
            }
        }
    }
}

query = 'enter-comment=' + el.elements['enter-comment'].value;

xmlhttp.open("POST","spotlight/comment.php?add=true",true);
xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
xmlhttp.send(query);
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T14:05:16+00:00Added an answer on May 28, 2026 at 2:05 pm

    Okay. Hello, spaghetti-code! 😉


    It’s hard to tell what exactly is going on, but one thing I noticed is this:

    When typing a comment, the moment the comment becomes too long and the height of the text field is animated, the JS console starts spewing uncaught RangeErrors (“Maximum call stack size exceeded”). So there’s something amiss there. And since you said the problem occurs after you add a long comment, I think it’s a safe bet this is what causing it.

    This error is usually indicative of an infinite loop. So look for that. Hint: you can use Firebug or Chrome WDT to inspect where in jQuery the RangeError occurs. It’s hard to tell because you’re using a minified version of jQuery, but my guess is that you’re using $() to create new DOM elements (in a loop, as said).


    Now, I don’t think anyone here is going to take the (possibly huge amount of) time necessary to debug this code in its current form. Maybe you’ll get lucky and someone will spot the problem, but I wouldn’t count on it.

    So, what else can you do? Well, now that you’ve experienced how to write spaghetti code, perhaps it’s time to go Object Oriented? Write your own types (or “classes”) so you can represent “objects” on a the page (e.g. a single comment, the comment list, the new comment field, etc.). These objects can keep references to the DOM nodes, as well as to the state of the “objects” they represent. Furthermore, they could have simple-to-call methods that wrap more complicated logic.

    The main goal of this is code readability. Really? Yes, really. I could preach about avoid things like strong coupling between HTML and JS using onclick and onmouseover attributes (it’s bad, m’kay?), but that is not the real goal of having an object-oriented JavaScript architecture. When your application starts getting more complex, it’s harder to keep track of what does what to what and where. By bundling your code into distinct pieces, it’s easier to reason about what’s going on. Instead of 30 lines of low-level code, you could have one function call (e.g. newComment.animate('open'), or something like that).

    On top of that, creating objects for every “object” on the page allows you to make them responsible for their own behaviour, and nothing but their own behaviour. When you take this really seriously (and many do), you call it the single responsibility principle.

    So I recommend you read about OO JavaScript. Leave jQuery out of it while you’re learning more about JavaScript itself. And then… start rewriting your application, bit by bit. Yes, it will take a lot of time. But it will be worth it, because your application will be much more maintainable.


    Useful resources:

    • JavaScript: The Good Parts by Douglas Crockford (ISBN: 978-0-596-51774-8)
    • Professional JavaScript for Web Developers by Nicholas Zakas (ISBN: 978-0-7645-7908-0)
    • Crockford on JavaScript (YouTube playlist, highly recommended)
    • Mozilla Developer Network
    • W3Fools.com
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This is a really weird problem that I have been having. When I download
I have this really weird bug. When I scroll down my table view, down
This is the second time that I have this really weird problem with WCF
Ok, this is a really weird one. I have an MPI program, where each
So I have this program that I really like, and it doesn't support Applescript.
Ok I have this problem that I've never had before, it's really bugging me.
I have read that you can do it, but would this really improve performance
This is really getting to me now.I have a form that loads when the
to me this is really weird, i have this menu: <!DOCTYPE html> <html> <head>
I'm experiencing some really weird object behaviours at the moment. I have this template

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.