473,325 Members | 2,671 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,325 software developers and data experts.

how to apply javascript without any event

hi....
i want to display current date and time of client side in the page. i have the javascript code also bt i dnt know how to use it in the page. the code is

Expand|Select|Wrap|Line Numbers
  1. function ShowTime()
  2. {
  3. var TimerKey
  4. var now = new Date()
  5. var Hours = now.getHours()
  6. var Minutes = now.getMinutes()
  7. var Seconds = now.getSeconds()
  8. TimeDisplay.innerText = ((Hours > 12) ? Hours - 12 : Hours) + ((Minutes < 10) ? ":0" : ":") + Minutes + ((Seconds < 10) ? ":0" : ":") + Seconds + ((Hours > 12) ? " PM" : " AM")
  9. window.status = ((Hours > 12) ? Hours - 12 : Hours) + ((Minutes < 10) ? ":0" : ":") + Minutes + ((Seconds < 10) ? ":0" : ":") + Seconds + ((Hours > 12) ? " PM" : " AM")
  10. TimerKey = setTimeout("ShowTime()",1000)
  11. }
  12.  
name of the file is showtime.js
please give me the instruction to use it
Feb 7 '08 #1
1 905
hi....
i want to display current date and time of client side in the page. i have the javascript code also bt i dnt know how to use it in the page. the code is

Expand|Select|Wrap|Line Numbers
  1. function ShowTime()
  2. {
  3. var TimerKey
  4. var now = new Date()
  5. var Hours = now.getHours()
  6. var Minutes = now.getMinutes()
  7. var Seconds = now.getSeconds()
  8. TimeDisplay.innerText = ((Hours > 12) ? Hours - 12 : Hours) + ((Minutes < 10) ? ":0" : ":") + Minutes + ((Seconds < 10) ? ":0" : ":") + Seconds + ((Hours > 12) ? " PM" : " AM")
  9. window.status = ((Hours > 12) ? Hours - 12 : Hours) + ((Minutes < 10) ? ":0" : ":") + Minutes + ((Seconds < 10) ? ":0" : ":") + Seconds + ((Hours > 12) ? " PM" : " AM")
  10. TimerKey = setTimeout("ShowTime()",1000)
  11. }
  12.  
name of the file is showtime.js
please give me the instruction to use it
In your HTML HEAD section.

include the JS file using

<script src="filename.js"></script>

Also somewhere you should define what "TimerDisplay" is...

Let us say there is a div as shown ..

<div id="timer"></div>

within head ....
<script>
startShowingTime()
{
TimerDisplay = document.getElementById("timer");
ShowTime();
}
</script>

Again, I am not a scripting expert. But you can use something like setTimeOut() event to periodically invoke ShowTime()
Feb 7 '08 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: planb | last post by:
Hi, I'd like to have a rollover like effect when a input field has the focus, any idea of how to do this with just CSS (easy enough with javascript)? What I'm thinking of is having a tips box...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.