Welcome guest. Before posting on our computer help forum, you must register. Click here it's easy and free.

Author Topic: Why doesn't this very simplistic function work?  (Read 4162 times)

0 Members and 1 Guest are viewing this topic.

BarryP

    Topic Starter


    Greenhorn

    • Experience: Experienced
    • OS: Windows 7
    Why doesn't this very simplistic function work?
    « on: December 06, 2013, 09:11:51 AM »
    This code displays the button then nothing happens when I click on it. Can someone please tell me why?  Thank you in advance for your reply.
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">

    <head>
       <title>Displaying Times and Dates</title>

     <script type="text/javaScript" Language="javaScript" >
         
         
       Function getData()  {
       
        var   now = ""
         var   localtime1 = ""
         var   utctime1 = ""
         var    myButton = document.getElementById("myButton");
       
          now = new Date();

          localtime1 = now.Tostring();
          utctime1 = now.toGMTString();
          alert("<strong>Local Time:<strong> '
          + Localtime1 + '
    ");
          alert("<strong>UTC Time:</strong> " + utctime1);
        }     

       Function test() {
       
       alert("Testing to see if this executed");

       }
    </script>
    </head>

    <body>

    <h1>Current Date and Time</h1>
    <input type="button" id="myButton" value="Get Date" onclick="getData();" />

    </body>


    </html>

    camerongray



      Expert
    • Thanked: 306
      • Yes
      • Cameron Gray - The Random Rambings of a Computer Geek
    • Certifications: List
    • Computer: Specs
    • Experience: Expert
    • OS: Mac OS
    Re: Why doesn't this very simplistic function work?
    « Reply #1 on: December 06, 2013, 08:53:38 PM »
    You are missing semicolons from these lines:
    Code: [Select]
    var   now = ""
         var   localtime1 = ""
         var   utctime1 = ""

    That said, there are other errors after that caused by strange capitalisation on things, Javascript is case sensitive so you need to take care to use the correct case.  Javascript uses "lowerCamelCase" so the first letter is always lowercase and the first letter of each word after this is a capital, you should adhere to this in your program to keep it neat.   You should also take care with your indentation as it's currently pretty messy and heard to read.  Finally, you no longer need the "language" attribute in the script tag as that is out of date, the 'type="text/javascript"' is all you should need nowadays.

    Salmon Trout

    • Guest
    Re: Why doesn't this very simplistic function work?
    « Reply #2 on: December 07, 2013, 02:41:15 AM »
    Just a little language note here... 'simplistic' is used about points raised in debate or argument and means "misleadingly over-simplified' - I think the word you need is 'simple'.