sound palyed by time of the day

this's me's Avatar, Join Date: Dec 2006
Newbie Member
any one knows what is wrong this code before i go crazy, i have tryed it, but no luck(i need help pls) and yes i have changed the times.
HTML Code:
<html>

<head>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1256">
<title>New Page 1</title>
</head>

<body>
<embed src="http://www.hypergurl.com/games/soundfiles/the_time_is.wav" hidden="true" autostart="false" name="soundfile1">
<script language="JavaScript">

day = new Date()
hr = day.getHours()
if (hr==1) {document.soundfile1.play()}
</script>
</body>

</html>
0
ever_thus's Avatar, Join Date: Jan 2007
Contributor
Your script is only executing once; when the page loads. When 1:00 arrives the page isn't testing the time anymore.

I'd use
Code:
<script language="JavaScript">
function timer {
       day = new Date()
       hr = day.getHours()
       if (hr==1) {document.soundfile1.play()}
        setTimeout ('timer()', 1000);
</script>
This function will call itself second (1000 miliseconds) and check the time again.

To start the process add this to your body element

<body onload='timer()'> ... </body>

Last edited by shabbir; 4Jan2007 at 06:56.. Reason: Code formating.
0
DaWei's Avatar, Join Date: Dec 2006
Team Leader
Off-topic, but possibly useful nugget of information for the OP's next post: Java != Javascript.
0
shabbir's Avatar, Join Date: Jul 2004
Go4Expert Founder
Moved from Java to HTML/DHTML/CSS - JavaScript/VBScript.
0
ever_thus's Avatar, Join Date: Jan 2007
Contributor
this's me, did my solution work?