DisplayTimeInStatusLine() - Help

J

Jamiil

Using Microsof Front Page, I am trying to display the time on the
Status Line, however, to no avail.
Here is a snip of the code code:
...\dev\JavaScript\DisplayTimeInStatusLine.js
<HTML>
<HEAD>
<script type="text/javascript">
//This function displays the time in the status line
//Invoke it once tho activate the clock; it will call itself from then
on.
function DisplayTimeInStatusLine(){
var d = new Date; //Get current time
var h = d.getHour; //Extract hours: 0 to 23
var m = d.getMinutes(); //Extract minutes: 0 to 59
var ampm = (h >= 12)?"PM":"AM"; //Is it am or pm
if(h > 12) h -= 12; //Convert 24-hour to 12-hour
if(h == 0) h = 12; //Convert 0 o'clock to midning
if(m < 10) m = "0" + m; //Convert 0 mins to 00 mins,etc
var t = h + ":" + m + ' ' + ampm; //Put it all together

defaultStattus = t; // Display it in the status line

// Arrange to do it all again in 1 min
setInterval(DisplayTimeInStatusLine(), 60000);
}
</SCRIPT>
</HEAD>
</HTML>
---------- end of snip 1 --------

...\dev\index.html
<head>
<!-- saved from url=(0014)about:internet -->
<meta http-equiv="Content-Language" content="en-us">
<meta name="GENERATOR" content="Microsoft FrontPage 5.0">
<meta name="ProgId" content="FrontPage.Editor.Document">
<meta http-equiv="Content-Type" content="text/html;
charset=windows-1252">
<title>Jamiil's Home Page</title>
<SCRIPT SRC="JavaScript/DisplayTimeInSatatusLine.js"></SCRIPT>
</head>

<body bgcolor="#000000" style="text-align: left"
onLoad="DisplayTimeInStatusLine();">
......
----- end of snip 2 -----

I am learning from a book called "JavaScript, The Definitive Guide, 3rd
Edition" by O'REILLY.

Can anyone help?

TIA
 
L

Lee

Jamiil said:
Using Microsof Front Page, I am trying to display the time on the
Status Line, however, to no avail.
defaultStattus = t; // Display it in the status line

Check the spelling.

Also note that modern browsers allow the user to disable changes
to the status line (and that people who want to see the time
displayed generally already have it displayed on their screen).


--
 
R

RobG

Jamiil said:
Using Microsof Front Page, I am trying to display the time on the
Status Line, however, to no avail.
Here is a snip of the code code:
..\dev\JavaScript\DisplayTimeInStatusLine.js
<HTML>
<HEAD>
<script type="text/javascript">
//This function displays the time in the status line
//Invoke it once tho activate the clock; it will call itself from then
on.
function DisplayTimeInStatusLine(){

It is a convention that only constructors start with a capital letter,
so make that:

function displayTimeInStatusLine(){

var d = new Date; //Get current time

You want to call Date as a constructor function, so add '()':

var d = new Date();

var h = d.getHour; //Extract hours: 0 to 23

getHours() (note the 's') is a method of a date object, so it needs ()
to call it:

var h = d.getHours(); //Extract hours: 0 to 23

var m = d.getMinutes(); //Extract minutes: 0 to 59
var ampm = (h >= 12)?"PM":"AM"; //Is it am or pm
if(h > 12) h -= 12; //Convert 24-hour to 12-hour
if(h == 0) h = 12; //Convert 0 o'clock to midning
if(m < 10) m = "0" + m; //Convert 0 mins to 00 mins,etc
var t = h + ":" + m + ' ' + ampm; //Put it all together

defaultStattus = t; // Display it in the status line

// Arrange to do it all again in 1 min
setInterval(DisplayTimeInStatusLine(), 60000);

The first argument to setInterval should be a string. Your function
will execute displayTimeInStatusLine() zillions of times per second -
but you will only notice that your browser runs slowly. All the CPU is
being sucked-up by calls to DisplayTimeInStatusLine():

setInterval('displayTimeInStatusLine()', 60000);


Incidentally, that will likely slowly drift off the correct time so that
it is either + or - 1 minute from the 'correct' system time - say you
start it one second before 3:05 pm, it won't call the function again
until one second before 3:06, so when it shows 3:06 it will be 3:07.

But in any case, many browsers (including mine) will not let you change
the status bar text with script, so you've totally wasted your time -
but hey, for the purpose of the demo...

[...]
 
J

Jamiil

Thanks everyone for the prompt help!
I did all the changes you folks suggested, but I still get one error in
Line 1 says the popup window.
Here is the new encarnation of the code

--- Snipt of code in .\dev\index.html ---

<%@ Language=JavaScript %>
<html>
<head>
<!-- saved from url=(0014)about:internet -->
<meta http-equiv="Content-Language" content="en-us">
<meta name="GENERATOR" content="Microsoft FrontPage 5.0">
<meta name="ProgId" content="FrontPage.Editor.Document">
<meta http-equiv="Content-Type" content="text/html;
charset=windows-1252">
<title>Jamiil's Home Page</title>
<SCRIPT SRC=".\JavaScript\DisplayTimeInSatatusBar.js"></SCRIPT>
</head>

--- Snip in .\dev\JavaScript\DisplayTimeInStatusBar.js
<HTML>
<HEAD>
<script type="text/javascript">
//This function displays the time in the status line
//Invoke it once tho activate the clock; it will call itself from then
on.
function displayTimeInStatusBar(){
var d = new Date(); //Get current time
var h = d.getHour(); //Extract hours: 0 to 23
var m = d.getMinutes(); //Extract minutes: 0 to 59
var ampm = (h >= 12)?"PM":"AM"; //Is it am or pm
if(h > 12) h -= 12; //Convert 24-hour to 12-hour
if(h == 0) h = 12; //Convert 0 o'clock to midning
if(m < 10) m = "0" + m; //Convert 0 mins to 00 mins,etc
var t = h + ":" + m + ' ' + ampm; //Put it all together

defaultStatus = t; // Display it in the status line

// Arrange to do it all again in 1 min
setInterval('displayTimeInStatusBar()', 60000);
}
</SCRIPT>
</HEAD>
</HTML>

Should I use tags in this file? is this OK?

Thanks
 
R

Randy Webb

Jamiil said the following on 5/10/2006 9:40 AM:
Thanks everyone for the prompt help!
I did all the changes you folks suggested, but I still get one error in
Line 1 says the popup window.
Here is the new encarnation of the code

--- Snipt of code in .\dev\index.html ---

<%@ Language=JavaScript %>
<html>
<head>
<!-- saved from url=(0014)about:internet -->
<meta http-equiv="Content-Language" content="en-us">
<meta name="GENERATOR" content="Microsoft FrontPage 5.0">
<meta name="ProgId" content="FrontPage.Editor.Document">
<meta http-equiv="Content-Type" content="text/html;
charset=windows-1252">
<title>Jamiil's Home Page</title>
<SCRIPT SRC=".\JavaScript\DisplayTimeInSatatusBar.js"></SCRIPT>
</head>

--- Snip in .\dev\JavaScript\DisplayTimeInStatusBar.js
<HTML>

syntax error. The only thing that goes in the external file is script
code, no tags. But you will still get an error unless you made a mistake
in your copy/paste. Your script tag references .\JavaScript.... but you
say it is in .\dev\JavaScript\... Those are not the same paths. And IE
will use a standard 404 page for the script source and again generate
errors.
 
J

Jamiil

Thanks for your prompt response Randy,
the tree directory looks like this
c:\dev\index.html
c:\dev\sound\sound_files.wav
c:\dev\JavaScript\DisplayTimeInStatusBar.js
......
When including the *.js, I used relative address
<html>
<head>
....
<SCRIPT SRC="JavaScript\DisplayTimeInSatatusBar.js"></SCRIPT>
</head>
..
I don't see a problem with this statement, however, I have been proven
wrong more than once.
Could you please elaborate a bit more on this issue?
And yes, you are rihgt! I still get the runtime error!!

TIA
 
R

Randy Webb

Jamiil said the following on 5/12/2006 7:08 AM:
Thanks for your prompt response Randy,

Thank you for quoting in the future.

If you want to post a followup via groups.google.com, don't use the
"Reply" link at the bottom of the article. Click on "show options" at
the top of the article, then click on the "Reply" at the bottom of the
article headers.

the tree directory looks like this
c:\dev\index.html
c:\dev\sound\sound_files.wav
c:\dev\JavaScript\DisplayTimeInStatusBar.js
......
When including the *.js, I used relative address
<html>
<head>
....
<SCRIPT SRC="JavaScript\DisplayTimeInSatatusBar.js"></SCRIPT>

That is not what you posted the first time though. But even then,
..\JavaScript and JavaScript are not the same path. For testing purposes,
put your .js file in the same folder. Resolve any and all errors, then
move it to the folder. Then, if you get errors you know it is a file
reference error. Is that the way your file is named as well? When
testing locally IE doesn't care about case, it will matter on a live
website though.
</head>
..
I don't see a problem with this statement, however, I have been proven
wrong more than once.
Could you please elaborate a bit more on this issue?

Which issue? The path issue? If you give a src attribute an improper
source file, then IE will get a "404 Page not Found" file and insert it
in the src since it can't find the file it was hunting. And since the
first few characters of that file are <html, it is a syntax error in the
script block.
And yes, you are rihgt! I still get the runtime error!!

Runtime Error or Syntax Error?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,774
Messages
2,569,599
Members
45,175
Latest member
Vinay Kumar_ Nevatia
Top