JavaScript

Moderators: None (Apply to moderate this forum)
Number of threads: 2058
Number of posts: 5158

This Forum Only
Post New Thread
Single Post View       Linear View       Threaded View      f

Report
Javascript Clock - help needed Posted by jeannot18 on 6 Nov 2005 at 4:43 PM
This message was edited by jeannot18 at 2005-11-6 18:46:53

Could someone tell me why this script is not working. I have been trying to find what is wrong but I can't find it. Many thanks.
JC (Newbie professional)
----------------------------------------------------------------------
<HTML>
<HEAD>
<TITLE>Current Time</TITLE>
</HEAD>

<BODY bgcolor="white">
<SCRIPT Language="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>



<BODY>

onLoad = "clock()"
<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>
----------------------------------------------------------------------


Report
Re: Javascript Clock - help needed Posted by mac_doggie on 7 Nov 2005 at 3:13 AM
: This message was edited by jeannot18 at 2005-11-6 18:46:53

: Could someone tell me why this script is not working. I have been trying to find what is wrong but I can't find it. Many thanks.
: JC (Newbie professional)
: ----------------------------------------------------------------------
: <HTML>
: <HEAD>
: <TITLE>Current Time</TITLE>
: </HEAD>
:
: <BODY bgcolor="white">
: <SCRIPT Language="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>
:
:
:
: <BODY>
:
: onLoad = "clock()"
: <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>
: ----------------------------------------------------------------------
:
:
:
First of all; You have two body tags....
second; the onload should be inside the bodytag, not behind it...

<HTML>
<HEAD>
<TITLE>Current Time</TITLE>
</HEAD>

<BODY bgcolor="white" onLoad = "clock()" >
<SCRIPT Language="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>



<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>

and then it works fine...
good luck...

-mac-
mailto:mac_doggie@hotmail.com
the Netherlands...


Report
Re: Javascript Clock - help needed Posted by jeannot18 on 7 Nov 2005 at 6:20 AM
Doggie you are a top man. This is what gets me frustated with Javascript (and other programming language I guessed), if you make a mistake it just does not work. What can I use to "debug" my script in Javascript? I am using note pad right now but is there a dedicated Javascript kind of writer that I could use to help me? Thanks again and see you probably very soon
JC
: :
: First of all; You have two body tags....
: second; the onload should be inside the bodytag, not behind it...
:
: <HTML>
: <HEAD>
: <TITLE>Current Time</TITLE>
: </HEAD>
:
: <BODY bgcolor="white" onLoad = "clock()" >
: <SCRIPT Language="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>
:
:
:
: <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>
:
: and then it works fine...
: good luck...
:
: -mac-
: mailto:mac_doggie@hotmail.com
: the Netherlands...
:
:
:

Report
Re: Javascript Clock - help needed Posted by mac_doggie on 7 Nov 2005 at 3:11 PM
: Doggie you are a top man. This is what gets me frustated with Javascript (and other programming language I guessed), if you make a mistake it just does not work. What can I use to "debug" my script in Javascript? I am using note pad right now but is there a dedicated Javascript kind of writer that I could use to help me? Thanks again and see you probably very soon
: JC
: : :
: : First of all; You have two body tags....
: : second; the onload should be inside the bodytag, not behind it...
: :
: : <HTML>
: : <HEAD>
: : <TITLE>Current Time</TITLE>
: : </HEAD>
: :
: : <BODY bgcolor="white" onLoad = "clock()" >
: : <SCRIPT Language="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>
: :
: :
: :
: : <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>
: :
: : and then it works fine...
: : good luck...
: :
: : -mac-
: : mailto:mac_doggie@hotmail.com
: : the Netherlands...
: :
: :
: :
:
:


I usualy edit my JavaScript/HTML and PHP in PSPAD or Textpad (both free to use) Not really debugging tools, but it colors your code and it are just nice editors...

For debugging JavaScript I usualy try the scripts in Mozilla Firefox, It gives better errormessages, and there are a lot of plugins that make a programmerslife much more pleasant.

And If you get errors try putting some alerts between your code so you can easily see where it goes wrong...


-mac-
mailto:mac_doggie@hotmail.com
the Netherlands...


Report
Re: Javascript Clock - help needed Posted by freeman_452003 on 8 Nov 2005 at 12:02 PM
: This message was edited by jeannot18 at 2005-11-6 18:46:53

: Could someone tell me why this script is not working. I have been trying to find what is wrong but I can't find it. Many thanks.
: JC (Newbie professional)
: ----------------------------------------------------------------------
: <HTML>
: <HEAD>
: <TITLE>Current Time</TITLE>
: </HEAD>
:
: <BODY bgcolor="white">
: <SCRIPT Language="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>
:
:
:
: <BODY>
:
: onLoad = "clock()"
: <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>
: ----------------------------------------------------------------------
:
:
: In this your onLoad() is on the outside of your body tag. Besides that you are perfectly all right. Change your body tag to

<body onload='clock()'>

Report
Re: Javascript Clock - help needed Posted by jeannot18 on 8 Nov 2005 at 1:09 PM
Thanks, got it corrected now.
JC

: : This message was edited by jeannot18 at 2005-11-6 18:46:53

: : Could someone tell me why this script is not working. I have been trying to find what is wrong but I can't find it. Many thanks.
: : JC (Newbie professional)
: : ----------------------------------------------------------------------
: : <HTML>
: : <HEAD>
: : <TITLE>Current Time</TITLE>
: : </HEAD>
: :
: : <BODY bgcolor="white">
: : <SCRIPT Language="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>
: :
: :
: :
: : <BODY>
: :
: : onLoad = "clock()"
: : <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>
: : ----------------------------------------------------------------------
: :
: :
: : In this your onLoad() is on the outside of your body tag. Besides that you are perfectly all right. Change your body tag to
:
: <body onload='clock()'>
:
:




 

Recent Jobs

Official Programmer's Heaven Blogs
Web Hosting | Browser and Social Games | Gadgets

Popular resources on Programmersheaven.com
Assembly | Basic | C | C# | C++ | Delphi | Flash | Java | JavaScript | Pascal | Perl | PHP | Python | Ruby | Visual Basic
© Copyright 2011 Programmersheaven.com - All rights reserved.
Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
Operated by CommunityHeaven, a BootstrapLabs company.