SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Member
    Join Date
    Jan 2005
    Location
    NY
    Posts
    17
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question this Javascript code doesnt work

    One said that it worked at his but it never works on mine:

    <body>
    <script type="text/javascript">
    function mf()
    {
    var d=new date()
    var time=d.get hours()
    }
    if (time<10)
    {
    alert("Good Morning!")
    }
    else
    {
    alert("Good Day")
    }
    </script>
    </body>

    <body>
    <form>
    <input type="button"
    onclick="mf()"
    value="Call function">
    </form>
    </body>
    </html>

    the alert doesnt pop up

    Please test this out and give me a fixed version

  2. #2
    Tranceoholic lilleman's Avatar
    Join Date
    Feb 2004
    Location
    Írebro, Sweden
    Posts
    2,716
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi,

    You have to put the IF condition inside of the function.
    I also changed some other things (you probably see what I've changed).

    HTML Code:
    <html>
     <head>
      <script type="text/javascript">
      function mf()
      {
        var d = new Date()
        var time = d.getHours()
       
        if (time<10)
        {
          alert("Good Morning!")
        }
        else
        {
          alert("Good Day")
        }
      }
      </script>
     </head>
    
     <body>
      <input type="button" onclick="mf()" value="Call function">
    </body>
    </html>
    Yours, Erik.
    ERIK RIKLUND :: Yes, I've been gone quite a while.

  3. #3
    SitePoint Member
    Join Date
    Jan 2005
    Location
    NY
    Posts
    17
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    tnx it works!

    ill post more often in this forum for help then with asp and php

  4. #4
    Tranceoholic lilleman's Avatar
    Join Date
    Feb 2004
    Location
    Írebro, Sweden
    Posts
    2,716
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi,

    Quote Originally Posted by ssunlimited
    ill post more often in this forum [...]
    That sounds like a plan. Also, it would be a good thing to introduce yourself.

    Yours, Erik.
    ERIK RIKLUND :: Yes, I've been gone quite a while.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •