I cannot to get over a simple noobie hurdle

This code from arcLab presents a simple date & time on a page:

<p>Date/Time: <span id="datetime"></span></p> //put on the page
<script>  //put in the header
var dt = new Date();
document.getElementById("datetime").innerHTML = dt.toLocaleString();

But, of course, it doesn’t work:

If you are able to publish this page, it makes it easier to check what’s wrong. I guess you entered the HTML
part in a wrong way.

What I was going to say in the last post, I couldn’t edit for some reason…

Try removing the script tags and putting the js in the JavaScript area, put the html bit in wherever you want the date to show up.


You are also able to put the whole content in the HTML Stack, just as is. You don’t have to separate it into Stacks page and header area.

Thanks for your input. This should be “stupid” simple. I grabbed the code from https://www.arclab.com/en/kb/htmlcss/display-date-time-javascript-php-ssi.html

I simply brought a rudimentary html stack onto a new stacks page, pasted the code (above), then put the script into the header.

I can’t publish the page right now. I re-up’d with GoDaddy for my sites–and trying to save money, the tech had me migrate my websites to a new directory structure. I think something isn’t set right, but I think it’s on his end.

I’d actually put the script in the header area. I moved it to the javascript area. No change.

Put all together into the HTML stack.

1 Like

Did you get rid of the <script> and </script>

Your solution worked. Now, here’s the thing: is this approach the “right approach” long term for things of this nature?

THanks for the input. I tried getting rid of the tags - no change.

That depends on the code. In that case, the JS Code had to be “below” the HTML code.

If you rewrite the JS code, it will work in header also.

Thanks very much for your help.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.