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

  • Home
  • SEARCH
  • 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 4543764
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T15:34:36+00:00 2026-05-21T15:34:36+00:00

For a simple project, I’m trying to display log output in a textarea. I

  • 0

For a simple project, I’m trying to display log output in a textarea. I have a log function, and would like the textarea to always be updated immediately whenever log is called. Unfortunately, it seems to only do the update once, and push everything at the same time (I’m using JQuery to set the value of the textarea, if that possibly matters). Here’s a basic example:

for (i = 0; i <= 100; i++) {
    $("textarea").html($("textarea").html() + "test" + i + "\n");
    $("textarea").scrollTop(9999999)
};

This spits out all the text into the textarea at once (note: you can see the results of these examples at this jsfiddle). This basic example is easily remedied by creating a timeout and using recursive function calls:

f = function(i) {
    if (i <= 100) {
        $("textarea").html($("textarea").html() + "test" + i + "\n");
        $("textarea").scrollTop(999999);
        setTimeout(function() { f(i+1); }, 0);
    }
};

f(1);

This version spits out the text into the textarea one line at a time, which is what I want. But using timeouts and callbacks in this manner does not seem practical in the setting of logging; every time I call log, I would have to provide a callback for all the functionality that I want to ever follow the log call.

Is there any way to achieve the desired effect without callbacks?

  • 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-21T15:34:37+00:00Added an answer on May 21, 2026 at 3:34 pm

    I think you might consider using :

    $("textarea").val(function(index, value) {
       return value + "test" + i + "\n"
    });
    

    instead of :

    $("textarea").html($("textarea").html() + "test" + i + "\n");
    

    or in general :

    $("textarea").val(NEWVAL)
    

    Also noted in the comments of your question, if you want to be able to notice “by eye” all the messages that arrives you’ll have to save them in a buffer and have something like (not tested) :

    var buffer = []
    
    function log(text) { buffer.push(text) }
    
    setInterval(function(){
      if (len(buffer)>0) {
        $("textarea").val(function(index, value) {
          return value + "\n" + buffer.shift()
        });
      }
    },500)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

We have a simple project where we read data from a socket and we
I'm new to Flex SDK and trying to implement a simple project using Doug
I'm trying to learn TDD by applying it to a simple project of mine.
Im using Eclipse 3.4, EclipseMe 1.7.9. Im trying to deploy/create package a simple project
I have a really simple ASP.NET web application and a web setup project that
Im sure this will be a simple one but have a project that started
I'm trying to write a simple raytracer as a hobby project and it's all
For a simple project I have to make large numbers (e.g. 4294967123) readable, so
I have started some simple project about Text Detection in images. And one of
After compiling a simple C++ project using Visual Studio 2008 on vista, everything runs

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.