Go4Expert

Go4Expert (http://www.go4expert.com/)
-   JavaScript and AJAX (http://www.go4expert.com/forums/javascript/)
-   -   sound palyed by time of the day (http://www.go4expert.com/forums/sound-palyed-time-day-t2193/)

this's me 11Dec2006 01:51

sound palyed by time of the day
 
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>


ever_thus 4Jan2007 00:17

Re: sound palyed by time of the day
 
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>

DaWei 4Jan2007 06:11

Re: sound palyed by time of the day
 
Off-topic, but possibly useful nugget of information for the OP's next post: Java != Javascript.

shabbir 4Jan2007 06:57

Re: sound palyed by time of the day
 
Moved from Java to HTML/DHTML/CSS - JavaScript/VBScript.

ever_thus 7Jan2007 06:40

Re: sound palyed by time of the day
 
this's me, did my solution work?


All times are GMT +5.5. The time now is 22:40.