1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

sound palyed by time of the day

Discussion in 'JavaScript and AJAX' started by this's me, Dec 10, 2006.

  1. this's me

    this's me New Member

    Joined:
    Dec 9, 2006
    Messages:
    1
    Likes Received:
    0
    Trophy Points:
    0
    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:
    <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>
     
  2. ever_thus

    ever_thus New Member

    Joined:
    Jan 3, 2007
    Messages:
    53
    Likes Received:
    0
    Trophy Points:
    0
    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 a moderator: Jan 4, 2007
  3. DaWei

    DaWei New Member

    Joined:
    Dec 6, 2006
    Messages:
    835
    Likes Received:
    5
    Trophy Points:
    0
    Occupation:
    Semi-retired EE
    Location:
    Texan now in Central NY
    Home Page:
    Off-topic, but possibly useful nugget of information for the OP's next post: Java != Javascript.
     
  4. shabbir

    shabbir Administrator Staff Member

    Joined:
    Jul 12, 2004
    Messages:
    15,283
    Likes Received:
    364
    Trophy Points:
    83
  5. ever_thus

    ever_thus New Member

    Joined:
    Jan 3, 2007
    Messages:
    53
    Likes Received:
    0
    Trophy Points:
    0
    this's me, did my solution work?
     

Share This Page