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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T12:39:51+00:00 2026-06-05T12:39:51+00:00

So thanks to stack overflow, I’ve determined that document.write is clobbering my webpage/program every

  • 0

So thanks to stack overflow, I’ve determined that document.write is clobbering my webpage/program every time it runs. I often see the answer is to use innerhtml and document.getElementById, however, in the following case, I can’t wrap my head around how it would be used below, seeing as how you have to assign an id for it to replace. I want the whole thing below to redraw in a single div. All it does is take that array, spit it out vertically, and highlight the number that matches the variable “speed”. That variable will change when you rerun the speedcounter function, so that the number that is highlighted will also change.

Is there a better way to do this?

And thanks for looking.

function speedcounter() {

var spx;
var speed = 3;
var sp=["0","3","4","4","4","5","6","7","8"];

document.write('   <h2>Speed</h2></br>');
document.write('<input type="button" onclick="addspeed();" value="+"><br />');   

 for (spx=8; spx>=0; spx--) {
    if (spx == speed) { 
      document.write('<font color=#00FF00>');
     }
    document.write(sp[spx]); 
    document.write('<font color=#000000><br />');
    }
 document.write ('<input type="button" onclick="remspeed();" value="-">');    
 }
  • 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-05T12:39:52+00:00Added an answer on June 5, 2026 at 12:39 pm

    If you don’t want to use jQuery for whatever reason, here’s a javascript-only solution.

    I created a div

    <div id="speed"></div>​
    

    and then use document.getElementById() and innerHTML to add HTML to it. I kept your code structure to illustrate how it would be done. I’m using += to add on to the existing HTML in the div. At the top of the function, I clear it. If you don’t do that you’ll get multiple copies of the output every time you call the function.

    function speedcounter() {
    document.getElementById('speed').innerHTML = "";
    var spx;
    var speed = 3;
    var sp=["0","3","4","4","4","5","6","7","8"];
    
    document.getElementById('speed').innerHTML += '<h2>Speed</h2></br>';
    document.getElementById('speed').innerHTML += '<input type="button" onclick="addspeed();" value="+"><br />';
    
     for (spx=8; spx>=0; spx--) {
        if (spx == speed) { 
            document.getElementById('speed').innerHTML += '<span style="color:#00FF00">' + sp[spx] + '</span><br />';
        } else {
            document.getElementById('speed').innerHTML += sp[spx] + "<br />"; 
        }
     }
     document.getElementById('speed').innerHTML += '<input type="button" onclick="remspeed();" value="-">';    
    }
    
    speedcounter();
    

    I also removed your font tag and replaced it with a span and inline CSS to set the color.

    Demo

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

Sidebar

Related Questions

Thanks to stack overflow I'm almost done with a programming problem that's been driving
Thanks to these stack overflow posts, I know how to make an nmap that
Thanks to Stack Overflow and you guys i successfully completed my first project (viz.
stack overflow ! I'm working on an application that manipulates SQL tables in a
First time posting on stack overflow. I've spent hours scouring over many Google searches
Thanks to Google and Stack Overflow, I think I understood the difference between regular
Let me thanks you guys at the Stack Overflow community for helping me with
I've been reading Stack Overflow questions for about 15 minutes now and every single
I read an answer to a question on Stack Overflow that contained the following
I have recently noticed that stack overflow for security reasons does not allow framing.

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.