0

I looked up what I could have done wrong but none of the given solutions solved the problem. Basically I want the date in the tag with the respective id but it does not work. Any ideas?

<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
</head>
<body style="background:url('../static/images/bg.jpeg') no-repeat center center fixed; background-size: cover;">

    <div style="background-color:black; height:200px; width:700px; position:center; color:green; overflow-y:scroll; margin:auto; margin-top:40px;">
        <a style="font-size:20px; font-weigth:bold; font-family:Lucida Console;">Logs:</a>
        <p><a id="logentry"></a>{{lomes}}</p>
    </div>

    <script type="text/javascript">
    new Date(day, month, year, hours, minutes, seconds)
    document.getElementById("logentry").innerHTML = Date();
    </script>

</body>
</html>

Solution: I used the code I found here and then did

document.getElementById("logentry").innerHTML = today;
jz22
  • 2,328
  • 5
  • 31
  • 50
  • 2
    Multiple problems: day, month, year, hours, minutes, seconds are all seem to be undefined. You don't save the Date object in a variable. You are trying to use a Date object as innerHTML – puelo Jul 11 '17 at 09:15
  • First line of script is unnecessary. Just use this `document.getElementById("logentry").innerHTML = (new Date()).toString()` – abhishekkannojia Jul 11 '17 at 09:15
  • You should always include the exact error you receive in your question. – Ashley Medway Jul 11 '17 at 09:26

2 Answers2

1

Your script contains bugs.

Remove the first line because it has not set in any variable and inside Date() method added variables are not defined.

A correct solution might be:

<script type="text/javascript">
    document.getElementById("logentry").innerHTML = Date();
</script>
Ashley Medway
  • 7,151
  • 7
  • 49
  • 71
Jaydeep Mor
  • 1,690
  • 3
  • 21
  • 39
0

Just use this inside your script tag

document.getElementById("logentry").innerHTML =new Date();

The first line isn''t a valid javascript call. You dont need it at all unless you want to specify a particular time to show.

Joey Pinto
  • 1,735
  • 1
  • 18
  • 34