Closed Thread Icon

Preserved Topic: JavaScript Time & Date that updates itself (Page 1 of 1) Pages that link to <a href="https://ozoneasylum.com/backlink?for=18431" title="Pages that link to Preserved Topic: JavaScript Time &amp;amp; Date that updates itself (Page 1 of 1)" rel="nofollow" >Preserved Topic: JavaScript Time &amp; Date that updates itself <span class="small">(Page 1 of 1)</span>\

 
sdna2k
Bipolar (III) Inmate

From: Plano, TX
Insane since: Jun 2001

posted posted 12-03-2001 20:50

I have this script (seen below) that displays (in the status bar) the time and date (which is always updating itself), but I need to have access to it with the actual Webpage itself (such as in the navigation bar, in plain text, not in a form text field)... can anyone help me?

*** This goes into the HEAD tag ***

<SCRIPT LANGUAGE="JavaScript">
<!-- Begin
function runDateAndTime() {
theTime = window.setTimeout("runDateAndTime()", 1000);
var today = new Date();
var display= today.toLocaleString();
status=display;
}
// End -->
</SCRIPT>

*** This goes into the BODY tag ***

onLoad="runDateAndTime()"

Emperor
Maniac (V) Mad Scientist with Finglongers

From: Cell 53, East Wing
Insane since: Jul 2001

posted posted 12-03-2001 20:53

sdna2k: Why not put it in a form and then use CSS to get rid of the borders and change the background colour. I'm sure there are scripts out there that do what you want but that might be the simplest method.

Emps


You're my wife now Dave

mr.maX
Maniac (V) Mad Scientist

From: Belgrade, Serbia
Insane since: Sep 2000

posted posted 12-03-2001 20:59

Simply create a layer where you want your clock to appear, like this:

<DIV ID="datetime"></DIV>

And modify status = display; line from your script to read:

document.getElementById("datetime").innerHTML = display;


sdna2k
Bipolar (III) Inmate

From: Plano, TX
Insane since: Jun 2001

posted posted 12-03-2001 21:01

I'me already using a variation of this script inside form elements, and I know it's picky, but I hate the text field look (even when camouflaged that way), and just wanted that clean "regular" text look so it would fit in with the navigation and graphics more smoothly.

sdna2k
Bipolar (III) Inmate

From: Plano, TX
Insane since: Jun 2001

posted posted 12-03-2001 21:04

mr.maX:

That looks to be the solution. With the DIVs though, would there be any problem in NS 3/4?

Thanks for the help, BTW.

Emperor
Maniac (V) Mad Scientist with Finglongers

From: Cell 53, East Wing
Insane since: Jul 2001

posted posted 12-03-2001 21:07

sdna2k: The reason I suggested doing things that way was the crossbrowser issues (OK it would have looked like a form in NS4.x but it would have worked). I'm sure there is a way around this - mr.maX should be able to sort it out I'd have thought!!

Emps


You're my wife now Dave

sdna2k
Bipolar (III) Inmate

From: Plano, TX
Insane since: Jun 2001

posted posted 12-03-2001 21:09

Emperor:
I appreciate your help as well. It's nice to be able to get some expert opinions on scripting when you're fairly new to this, as I am.

mr.maX
Maniac (V) Mad Scientist

From: Belgrade, Serbia
Insane since: Sep 2000

posted posted 12-03-2001 21:14

This cannot be done in NN3 since it doesn't have support for DHTML. But, it can be done in most major web browsers (NN4/6, Mozilla & IE). Anyway, to make it work in NN4 and older versions of IE, add the following function:

function changeText(layer, text) {
&nbsp;&nbsp;&nbsp;&nbsp;if (document.getElementById) {
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;document.getElementById(layer).innerHTML = text;
&nbsp;&nbsp;&nbsp;&nbsp;} else
&nbsp;&nbsp;&nbsp;&nbsp;if (document.all) {
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;document.all[layer].innerHTML = text;
&nbsp;&nbsp;&nbsp;&nbsp;} else
&nbsp;&nbsp;&nbsp;&nbsp;if (document.layers) {
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;document.layers[layer].document.open();
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;document.layers[layer].document.write(text);
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;document.layers[layer].document.close();
&nbsp;&nbsp;&nbsp;&nbsp;}
}

And instead of status = display; line use this:

changeText("datetime", display);


sdna2k
Bipolar (III) Inmate

From: Plano, TX
Insane since: Jun 2001

posted posted 12-03-2001 21:30

I'm getting greedy now... but how easy would that first DIV thing be to integrate into a table? And can the date/time output be colored and bolded with tags?

Thanks!

sdna2k
Bipolar (III) Inmate

From: Plano, TX
Insane since: Jun 2001

posted posted 12-03-2001 21:39

mr.maX:

I tried the NN4 and older IE function you created, but as I had it implemented, it was still causing a JavaScript error in NN 4.5 and 4.7. I put that function into the other script with all the other items unchanged, so I'm wondering and assuming that I botched the implementation. Can you shed any light on this for me... maybe putting all three together, or?

mr.maX
Maniac (V) Mad Scientist

From: Belgrade, Serbia
Insane since: Sep 2000

posted posted 12-03-2001 21:41

You can put that layer (<DIV> tag) wherever you want... And to modify text output simply add CSS definition to that layer, something like this:

<DIV ID="datetime" STYLE="color:red;font-weight:bold;"></DIV>


« BackwardsOnwards »

Show Forum Drop Down Menu