skip to Main Content

I want to make it that when a user opens this page it will be displayed LIVE FDP REPORT AS OF {Todays date time}

enter image description

the title that needs to have todays date

I tried to use Javascript to implement this:

script<
document.getElementById("current_date").value = Date();
></script>
<input id="current_date" readonly></>

2

Answers


  1. The JS code to set the value of your input is correct – although it could be improved by including the new keyword.

    The issue seems to be with how you’ve structured your HTML. The script needs to be HTML tags which contain the JS logic.

    Here’s a full example of how the entire HTML should look, in a simplified example. I’m sure your actual page will have more code than this, but the important part is the <script> tag, and where it’s located:

    <!DOCTYPE html>
    <html>
    
    <head>
      <title>Your page title goes here</title>
    </head>
    
    <body>
      <input id="current_date" readonly />
      <script>
        const displayDate = () => document.getElementById("current_date").value = new Date();
      
        displayDate(); // display on load
        setInterval(displayDate, 1000); // update every second
      </script>
    </body>
    
    </html>
    Login or Signup to reply.
  2. <!DOCTYPE html>
    <html>
    <head>
      <title>LIVE FDP REPORT AS OF <span id="current_date"></span></title>
    </head>
    <body>
    <!-- date -->
    <script>
    document.getElementById("current_date").textContent = new Date().toLocaleString();
    </script>
    </body>
    </html>
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search