Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New to the CF scene
    Join Date
    Feb 2009
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Unhappy Stuck on linking variable

    I am trying to link the variable (m) to the getMonth() function below it, or replace it whatever I need to do. I want the month to be displayed in words instead of numbers. Thanks if you can help.



    <script language="javascript">

    Date.prototype.getMonthName = function()
    {
    var m = ['January','February','March','April','May','June','July',
    'August','September','October','November','December'];
    return m[this.getMonth()];
    }

    var clockID = 0;
    function UpdateClock() {
    if(clockID) {
    clearTimeout(clockID);
    clockID = 0;
    }
    var tDate = new Date();
    document.theClock.theTime.value = ""
    + tDate.getMonth() + " "
    + tDate.getDay() + ", "
    + tDate.getYear() + " "
    + tDate.getHours() + ":"
    + tDate.getMinutes() + ":"
    + tDate.getSeconds();

    clockID = setTimeout("UpdateClock()", 1000);
    }
    function StartClock() {
    clockID = setTimeout("UpdateClock()", 500);
    }
    function KillClock() {
    if(clockID) {
    clearTimeout(clockID);
    clockID = 0;
    }
    }

    </script>

    <form name="theClock" class="myform">
    <input type="text" name="theTime" size="25" />
    </form>

  • #2
    Regular Coder
    Join Date
    Feb 2009
    Location
    NJ, USA
    Posts
    476
    Thanks
    2
    Thanked 70 Times in 69 Posts
    Actually, you wrote it correctly. That prototype function is fine. The problem is with the lines:

    Code:
       var tDate = new Date();
       document.theClock.theTime.value = ""  
       + tDate.getMonth() + " "
       + tDate.getDay() + ", "
       + tDate.getYear() + "    "
       + tDate.getHours() + ":" 
       + tDate.getMinutes() + ":" 
       + tDate.getSeconds();
    These need to have the plus sign at the end of the lines, so that the javascript interpreter won't think that you just left out a semicolon and treat it as an "end line."

    Code:
    var tDate = new Date();
    document.theClock.theTime.value = tDate.getMonthName() + " " + 
       tDate.getDate() + ", " + 
       tDate.getFullYear() + " " + 
       tDate.getHours() + ":" + 
       tDate.getMinutes() + ":"    + 
       tDate.getSeconds();
    Also, I replaced getDay() with getDate() (as getDay gets the day of the week, 0-6), and getYear() with getFullYear().


  •  

    Tags for this Thread

    Posting Permissions

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