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 8434681
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T06:43:26+00:00 2026-06-10T06:43:26+00:00

This function is running continuously without initiating a loop. The setTimeout is to allow

  • 0

This function is running continuously without initiating a loop.

The setTimeout is to allow the refreshTags function to run.

I’m sure it’s not the best-written script – I’m no guru – but any ideas on why this script is running in an endless loop?

function addTag() 
{
console.log('running'); 
refreshTags(); 
var t = document.getElementById('existingTags').textContent.match(/tag1/); 
var u = 'tag1'; 
if (t == u) {alert('This ticket has already been resolved by our team.')}; 
if (t != u) 
    {
    refreshTags();
    setTimeout(function() 
    {
        document.getElementById('tagToAdd').value = 'tag1';
        document.getElementById('tagSubmit').click(); 
        alert('Ticket resolved!'); 
    }, 2000)
}; 
}

Edit: code calling addTag below.

var resolveButton = document.createElement("a");
resolveButton.href = '#';
resolveButton.innerHTML = '<span>Resolve</span>';
resolveButton.setAttribute("onClick", "addTag()");
resolveButton.setAttribute("type", "button");
resolveButton.setAttribute("class", "button1");

var cha = document.getElementById('chatter_view');
cha.parentNode.insertBefore(resolveButton, cha);
  • 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-06-10T06:43:28+00:00Added an answer on June 10, 2026 at 6:43 am

    Instead of trying to answer why this particular piece of code has an infinite loop, I’ll attempt to answer the bigger question “How do you prevent and debug infinite loops?”.

    One of the best defenses I’ve found is to structure your code so control is always flowing in one direction. You have a number of different layers here:

    • the onclick event handler is calling into addTag()
    • addTag() is calling refreshTags()
    • addTag() is calling a setTimeout, which later triggers a click on the DOM.

    A simple fix to keep your code flowing in one direction is to create dedicated event handlers, e.g. resolveButtonOnclick() { addTag() }. resolveButtonOnclick is only ever called from the resolveButton’s onclick handler. This makes it much easier to audit your code. You’ve already put a console.log('running') at the top of your addTag() function. Now, if you put a console.log() in resolveButtonOnclick() you’ll know right away if the onclick handler is included in your infinite loop.

    We can’t see your code, but if refreshTags() calls addTag() you would have a circular control flow — these aren’t always bad, but you need to be extra careful that they terminate at some point.

    The biggest circular control flow you may have is that addTag() is calling back into the DOM with the .click() method. It would be better, faster and cleaner to submit the form directly from the Javascript or use an XHR.

    To debug this loop, you are one the right track with the console.log()s. Add more of them (e.g. every place you call addTag()) and figure out where it is being called from. The other thing you could try is using Chrome’s DevTools: add a ‘debugger;’ call to the top of addTag() and examine the stack trace.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Code is not running on .click when I have this: $(.cancel).click(function() { alert(got here);
I've been using this function to check if a process is running or not.
I've read numerous similar questions, but the answers simply didn't work. Running this function
I made this function to verify a user's twitter credentials. Its running on two
I have this code running in my onDestroy function: @Override protected void onDestroy() {
Possible Duplicate: calling ASP function from javascript okay running this code : <script type=text/javascript>
I have this code running great in ff, opera and chrome: <script type=text/javascript> $(document).ready(function(){
I have this script, running on a links list: $('li#linkcat-25 a').bind('click', function (e) {
When I am running this function the value is showing up as 26. I
I'm using mongoose in a script that is not meant to run continuously, and

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.