Need help fixing setInterval issue in JavaScript

MrAndrew1337

Yesterday, I was informed about setInterval to perform a task or function after a certain number of milliseconds. I have the interval working in my code, but each time it creates a new text line with the date. I want it to replace the previous one after each interval has ended. I tried fixing this by defining the text and date as a variable to be called, but that doesn't work either. Also, for anybody who is interested, here's the link to my question yesterday, which received very helpful responses.

<html>
<head>
<title>Time Stuff Page</title>

</head>
<link href="main.css" rel="stylesheet" type="text/css">
<body>
    <!-- adding color style for demo date buttons via CSS style tag->
<style type="text/css">
    #demo {
        color:red;
         }
    #demo2 {
        color:blue;
        }   
    </style>

<!-- Display date in paragraph -->
<button onclick="getElementById('demo').innerHTML=Date()">The time is? (from innerhtml)</button>
<p id="demo"></p>

<!-- Display date by calling a JS function -->
<button onclick="displayDate()">The time is? (from javascript)</button>
<p id="demo2"></p>

<!-- Display date inside "this" button -->
<button onclick="this.innerHTML=Date()">The time is? (display in button)</button>

<p></p>

<script language="javascript"> 
function displayDate() {
document.getElementById("demo2").innerHTML = Date();
}

var savedate = Date();
document.write("You loaded the page at: "+savedate);

//constantly updated date();
constantDate = function() {
var date = Date();
var timetext = "<br />Updated time is: "+date;
    document.write(timetext);
}

function checkDate() {
setInterval(function(){ constantDate(); }, 10);
}

checkDate();



</script>
</body>
</html>
lukbl

Create similar function to displayDate:

function displayDate2() {
   var timetext = "Updated time is: "+Date();
   document.getElementById("demo3").innerHTML =timetext;
}

You also need to add another paragraph to the body:

<p id="demo3"></p>

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Need help in identifying and fixing SSLPeerUnverifiedException

From Dev

Need help fixing a game I made in Python

From Dev

Need help fixing the syntax for this LEFT OUTER JOIN

From Dev

I need help fixing this hangman function

From Dev

Need help fixing strange cin behavior

From Dev

Need Help Fixing A Bug In Snake Game

From Dev

Need CSS/HTML help fixing navigation in IE

From Dev

I need help fixing this hangman function

From Dev

Need help fixing a segmentation fault (core dumped)

From Dev

Need help fixing my nginx server

From Dev

javascript: the "this" issue in setInterval (again)

From Dev

javascript setInterval timer issue

From Dev

need help fixing 500 error python/flask app

From Dev

Need help fixing my error on Notice: Array to string conversion in

From Dev

Need help fixing my implementation of RK4

From Dev

Need help fixing a vba Error '1004' after editing a section of code

From Dev

Need help fixing my error on Notice: Array to string conversion in

From Dev

Need help fixing CSS for a GTK theme for Gnome Shell

From Dev

Need help fixing top bar inside another div with scroll

From Dev

Need help fixing my isotope.js [jquery and html code]

From Dev

Need help fixing broken nautilus directory links on launcher

From Dev

I need help fixing my code - very fragile

From Dev

Need help fixing a random sentence generator that uses for loops and list's

From Dev

Need some help in fixing the Spark streaming dependency (Scala sbt)

From Dev

Need Help fixing incorrect output to console window.

From Dev

Need help fixing the output of this Higher Order Function.

From Dev

Need help to solve function issue

From Dev

Need Help in Jquery issue for Filters

From Dev

Need help on "this" in Javascript

Related Related

  1. 1

    Need help in identifying and fixing SSLPeerUnverifiedException

  2. 2

    Need help fixing a game I made in Python

  3. 3

    Need help fixing the syntax for this LEFT OUTER JOIN

  4. 4

    I need help fixing this hangman function

  5. 5

    Need help fixing strange cin behavior

  6. 6

    Need Help Fixing A Bug In Snake Game

  7. 7

    Need CSS/HTML help fixing navigation in IE

  8. 8

    I need help fixing this hangman function

  9. 9

    Need help fixing a segmentation fault (core dumped)

  10. 10

    Need help fixing my nginx server

  11. 11

    javascript: the "this" issue in setInterval (again)

  12. 12

    javascript setInterval timer issue

  13. 13

    need help fixing 500 error python/flask app

  14. 14

    Need help fixing my error on Notice: Array to string conversion in

  15. 15

    Need help fixing my implementation of RK4

  16. 16

    Need help fixing a vba Error '1004' after editing a section of code

  17. 17

    Need help fixing my error on Notice: Array to string conversion in

  18. 18

    Need help fixing CSS for a GTK theme for Gnome Shell

  19. 19

    Need help fixing top bar inside another div with scroll

  20. 20

    Need help fixing my isotope.js [jquery and html code]

  21. 21

    Need help fixing broken nautilus directory links on launcher

  22. 22

    I need help fixing my code - very fragile

  23. 23

    Need help fixing a random sentence generator that uses for loops and list's

  24. 24

    Need some help in fixing the Spark streaming dependency (Scala sbt)

  25. 25

    Need Help fixing incorrect output to console window.

  26. 26

    Need help fixing the output of this Higher Order Function.

  27. 27

    Need help to solve function issue

  28. 28

    Need Help in Jquery issue for Filters

  29. 29

    Need help on "this" in Javascript

HotTag

Archive