Go Back   CodingForums.com > :: Client side development > JavaScript programming

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 06-22-2009, 06:53 PM   PM User | #1
effpeetee
Senior Coder

 
effpeetee's Avatar
 
Join Date: Feb 2007
Location: Clapham Junction - London SW
Posts: 4,884
Thanks: 228
Thanked 204 Times in 203 Posts
effpeetee is an unknown quantity at this point
Exclamation Why does this supplied code not work?

I have put this code together from a tuition site, but I cannot get it to work.
Some of the instructions were ambiguous so I may have done it wrong.(the story of my life.) Any help gratefully received.

Frank alias effpeetee.

Code:
<!doctype html public "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<script type="text/javascript">
function clock(){
  var time = new Date()
  var hr = time.getHours()
  var min = time.getMinutes()
  var sec = time.getSeconds()
  if(hr < 10){
    hr = " " + hr
    }
  if(min < 10){
    min = "0" + min
    }
  if(sec < 10){
    sec = "0" + sec
    } 
  document.clock.digits.value = hr + ":" + min + ":" + sec
  setTimeout("clock()", 1000)
  }
</script>
</head>
<body >
<script type="text/javascript>
onLoad = "clock()"
</script>

<FORM name="clock">
 <FONT face="Courier New,Courier" size=4>
 <INPUT type="text"  name="digits"
    size=8 maxlength=8 value="Loading">
 </FONT>
 </FORM>
</body>
</html>
__________________
* Sources (updated: 21.11.2012.
Using Windows 8 Professional. 64bit with HP Photosmart 5510 printer Very useful site here.

Last edited by effpeetee; 06-23-2009 at 02:08 PM..
effpeetee is offline   Reply With Quote
Old 06-22-2009, 06:57 PM   PM User | #2
mike182uk
Regular Coder

 
Join Date: May 2008
Posts: 135
Thanks: 13
Thanked 10 Times in 10 Posts
mike182uk is an unknown quantity at this point
Quote:
Code:
<script type="text/javascript>
onLoad = "clock()"
</script>
this here aint doing anything. try this

Code:
<body onload="clock()">
so when the body loads, execute the clock function
mike182uk is offline   Reply With Quote
Old 06-22-2009, 07:07 PM   PM User | #3
effpeetee
Senior Coder

 
effpeetee's Avatar
 
Join Date: Feb 2007
Location: Clapham Junction - London SW
Posts: 4,884
Thanks: 228
Thanked 204 Times in 203 Posts
effpeetee is an unknown quantity at this point
Thanks mike182uk,

I thought that was probably one of the parts I did not quite understand. Your modification works perfectly. Many thanks.
Up until now, I have been a cut and paste (pinch someone elses code) man.
I am trying to come to terms with javascript.

Back to the grindstone.

Frank
__________________
* Sources (updated: 21.11.2012.
Using Windows 8 Professional. 64bit with HP Photosmart 5510 printer Very useful site here.
effpeetee is offline   Reply With Quote
Old 06-22-2009, 07:21 PM   PM User | #4
mike182uk
Regular Coder

 
Join Date: May 2008
Posts: 135
Thanks: 13
Thanked 10 Times in 10 Posts
mike182uk is an unknown quantity at this point
We all have to start somewhere :-)
mike182uk is offline   Reply With Quote
Old 06-23-2009, 02:07 PM   PM User | #5
effpeetee
Senior Coder

 
effpeetee's Avatar
 
Join Date: Feb 2007
Location: Clapham Junction - London SW
Posts: 4,884
Thanks: 228
Thanked 204 Times in 203 Posts
effpeetee is an unknown quantity at this point
Quote:
Originally Posted by mike182uk View Post
We all have to start somewhere :-)
I am 84 yrs old in September.
Perhaps I have left it a bit late.

but -

Nil desperandum.

Nothing ventured, nothing gained.

Frank - alias effpeetee
__________________
* Sources (updated: 21.11.2012.
Using Windows 8 Professional. 64bit with HP Photosmart 5510 printer Very useful site here.

Last edited by effpeetee; 06-23-2009 at 02:15 PM..
effpeetee is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 04:20 PM.


Advertisement
Log in to turn off these ads.