Page 1 of 2 12 LastLast
Results 1 to 10 of 11

Thread: How to make this script display the events for the whole year?

  1. #1
    Join Date
    Aug 2006
    Posts
    34
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default How to make this script display the events for the whole year?

    Hi guys,
    I use the script below to display on our college's intranet a birthday greetings or event for that day. My problem is that the script can only be used for one particular month only. I have to change/update it for next month.
    My problem is that, sometime i forget to change/update the birthday list for the next month and the script will "recycle" the list and display the birthday greetings of the previous month. And this is very embarrasing.
    Is there any way that i can modify the script to make it display the birthday greeting and events for the whole year. This will definitely save me a lot of time and embarrasment.
    Thank you.

    <SCRIPT LANGUAGE="JavaScript">
    <!--

    var ar = new Array(".",
    "Happy Birthday to John",
    ".",
    ".",
    ".",
    "Happy 10th Anniversary to Max and Jill",
    ".",
    ".",
    ".",
    ".",
    ".",
    "Happy Birthday to Trisha",
    ".",
    ".",
    ".",
    ".",
    ".",
    ".",
    ".",
    ".",
    ".",
    "Happy brithday to Hannah",
    ".",
    ".",
    ".",
    "Happy Birthday to Miriam",
    ".",
    ".",
    ".",
    "Tomorrow is the last day to submit your assignment.",
    ".");

    var now = new Date();
    var num = now.getDate() - 1;
    num %= ar.length;
    document.write(ar[num]);

    // -->
    </SCRIPT>
    Last edited by terkini; 08-20-2006 at 04:41 PM.

  2. #2
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    Hm, that's a bit ugly, isn't it? Try this instead:
    Code:
    <script type="text/javascript">
      String.prototype.isDMString = function() {
        var a;
        return (
          /^\d{2}\/\d{2}$/.test(this) &&
          (a = this.match(/d{2}/))[0] * a[1] > 0 &&
          a[0] <= 31 &&
          a[1] <= 12
        );
      };
    
      Number.prototype.pad = function(len) {
        var n = this.toString();
        while(n.length < len)
          n = "0" + n;
        return n;
      };
    
      function Calendar() {
        var currDate = "01/01";
        for(var i = 0; i < arguments.length; ++i)
          if(arguments[i].isDMString()) {
            currDate = arguments[i];
            if(!this[currDate]) this[currDate] = [];
          } else this[currDate].push(arguments[i]);
      }
    
      Calendar.prototype.addEvent = function(date, event) {
        if(typeof date !== 'string' || !date.isDMString())
          return false;
        if(!this[date]) this[date] = [];
        this[date].push(event);
        return true;
      };
    
      Calendar.prototype.getTodaysEvents = function() {
        var now;
        return this[(now = new Date()).getDate() + (now.getMonth() + 1).pad(2)];
      };
    
      var cal = new Calendar(
        "02/01", "Happy Birthday to John",
        "06/01", "Happy Birthday to Max", "Happy Birthday to Jill",
        "12/01", "Happy Birthday to Trisha",
        "22/01", "Happy Birthday to Hannah",
        "26/01", "Happy Birthday to Miriam",
        "30/01", "Tomorrow is the last day to submit your assignment."
      );
    
      document.write(cal.getTodaysEvents().join("<br>"));
    </script>
    Untested.
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

  3. #3
    Join Date
    Aug 2006
    Posts
    34
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Quote Originally Posted by Twey
    Hm, that's a bit ugly, isn't it? Try this instead:
    Code:
    <script type="text/javascript">
      String.prototype.isDMString = function() {
        var a;
        return (
          /^\d{2}\/\d{2}$/.test(this) &&
          (a = this.match(/d{2}/))[0] * a[1] > 0 &&
          a[0] <= 31 &&
          a[1] <= 12
        );
      };
    
      Number.prototype.pad = function(len) {
        var n = this.toString();
        while(n.length < len)
          n = "0" + n;
        return n;
      };
    
      function Calendar() {
        var currDate = "01/01";
        for(var i = 0; i < arguments.length; ++i)
          if(arguments[i].isDMString()) {
            currDate = arguments[i];
            if(!this[currDate]) this[currDate] = [];
          } else this[currDate].push(arguments[i]);
      }
    
      Calendar.prototype.addEvent = function(date, event) {
        if(typeof date !== 'string' || !date.isDMString())
          return false;
        if(!this[date]) this[date] = [];
        this[date].push(event);
        return true;
      };
    
      Calendar.prototype.getTodaysEvents = function() {
        var now;
        return this[(now = new Date()).getDate() + (now.getMonth() + 1).pad(2)];
      };
    
      var cal = new Calendar(
        "02/01", "Happy Birthday to John",
        "06/01", "Happy Birthday to Max", "Happy Birthday to Jill",
        "12/01", "Happy Birthday to Trisha",
        "22/01", "Happy Birthday to Hannah",
        "26/01", "Happy Birthday to Miriam",
        "30/01", "Tomorrow is the last day to submit your assignment."
      );
    
      document.write(cal.getTodaysEvents().join("<br>"));
    </script>
    Untested.
    Professor Twey,
    Thanks for your great effort in re-writing the codes. Unfortunately, when i run it, nothing appeared on the screen. For your information, I have also modified the dates to August so that my PC can displayed it, but still nothing appeared on the screen. Another thing that I would like the script to do is to enable me to decide the color and type of fonts used in the birthday greeting. For the guys, I want to use Times Roman in black and for girls, I want to use tahoma or arial in blue. I really hope somebody can help me on this.

    Here are the javascripts codes that i tried to run:

    <script type="text/javascript">
    String.prototype.isDMString = function() {
    var a;
    return (
    /^\d{2}\/\d{2}$/.test(this) &&
    (a = this.match(/d{2}/))[0] * a[1] > 0 &&
    a[0] <= 31 &&
    a[1] <= 12
    );
    };

    Number.prototype.pad = function(len) {
    var n = this.toString();
    while(n.length < len)
    n = "0" + n;
    return n;
    };

    function Calendar() {
    var currDate = "01/01";
    for(var i = 0; i < arguments.length; ++i)
    if(arguments[i].isDMString()) {
    currDate = arguments[i];
    if(!this[currDate]) this[currDate] = [];
    } else this[currDate].push(arguments[i]);
    }

    Calendar.prototype.addEvent = function(date, event) {
    if(typeof date !== 'string' || !date.isDMString())
    return false;
    if(!this[date]) this[date] = [];
    this[date].push(event);
    return true;
    };

    Calendar.prototype.getTodaysEvents = function() {
    var now;
    return this[(now = new Date()).getDate() + (now.getMonth() + 1).pad(2)];
    };

    var cal = new Calendar(
    "19/08", "Happy Birthday to John",
    "20/08", "Happy Birthday to Max", "Happy Birthday to Jill",
    "21/08", "Happy Birthday to Trisha",
    "22/08", "Happy Birthday to Hannah",
    "23/08", "Happy Birthday to Miriam",
    "24/08", "Tomorrow is the last day to submit your assignment."
    );

    document.write(cal.getTodaysEvents().join("<br>"));
    </script>

  4. #4
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    I did warn you it was untested This is the one that works:
    Code:
    <script type="text/javascript">
      String.prototype.isDMString = function() {
        var a;
        return (
          /^\d{2}\/\d{2}$/.test(this) &&
          (a = this.match(/(\d{2})\/(\d{2})/))[1] * a[2] > 0 &&
          a[1] <= 31 &&
          a[2] <= 12
        );
      };
    
      Number.prototype.pad = function(len) {
        var n = this.toString();
        while(n.length < len)
          n = "0" + n;
        return n;
      };
    
      function Calendar() {
        if(!arguments[0].isDMString) return;
        for(var i = 0; i < arguments.length; ++i)
          if(arguments[i].isDMString()) {
            currDate = arguments[i];
            if(!this[currDate]) this[currDate] = [];
          } else {
            this.addEvent(currDate, arguments[i]);
          }
      }
    
      Calendar.prototype.addEvent = function(dte, event) {
    
        if(typeof dte !== 'string' || !dte.isDMString())
          return false;
        if(!this[dte]) this[dte] = [];
        this[dte].push(event);
        return true;
      };
    
      Calendar.prototype.getTodaysEvents = function() {
        var now;
        return (this[(now = new Date()).getDate().pad(2) + "/" + (now.getMonth() + 1).pad(2)] || []);
      };
    
      Calendar.prototype.toString = function() {
        var op = "";
        for(var i in this) {
          if(!i.isDMString()) continue;
          op += "\n" + i + ": " + this[i].join(", ");
        }
        return op;
      };
    
      // NOTE: DD/MM format.  I'm a Brit. :-P
      var cal = new Calendar(
        "02/01", "Happy Birthday to John",
        "06/01", "Happy Birthday to Max", "Happy Birthday to Jill",
        "12/01", "Happy Birthday to Trisha",
        "22/01", "Happy Birthday to Hannah",
        "26/01", "Happy Birthday to Miriam",
        "30/01", "Tomorrow is the last day to submit your assignment."
      );
    
      document.write(cal.getTodaysEvents().join("<br>"));
    </script>
    Another thing that I would like the script to do is to enable me to decide the color and type of fonts used in the birthday greeting. For the guys, I want to use Times Roman in black and for girls, I want to use tahoma or arial in blue.
    You can include <span> or (shudder) <font> tags just as you would in plain HTML. Just remember to escape quotes; for example,
    Code:
    <span style="color:blue;">Happy Birthday to John</span>
    becomes:
    Code:
    "<span style=\"color:blue;\">Happy Birthday to John</span>"
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

  5. #5
    Join Date
    Aug 2006
    Posts
    34
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Quote Originally Posted by Twey
    I did warn you it was untested This is the one that works:
    Code:
    <script type="text/javascript">
      String.prototype.isDMString = function() {
        var a;
        return (
          /^\d{2}\/\d{2}$/.test(this) &&
          (a = this.match(/(\d{2})\/(\d{2})/))[1] * a[2] > 0 &&
          a[1] <= 31 &&
          a[2] <= 12
        );
      };
    
      Number.prototype.pad = function(len) {
        var n = this.toString();
        while(n.length < len)
          n = "0" + n;
        return n;
      };
    
      function Calendar() {
        if(!arguments[0].isDMString) return;
        for(var i = 0; i < arguments.length; ++i)
          if(arguments[i].isDMString()) {
            currDate = arguments[i];
            if(!this[currDate]) this[currDate] = [];
          } else {
            this.addEvent(currDate, arguments[i]);
          }
      }
    
      Calendar.prototype.addEvent = function(dte, event) {
    
        if(typeof dte !== 'string' || !dte.isDMString())
          return false;
        if(!this[dte]) this[dte] = [];
        this[dte].push(event);
        return true;
      };
    
      Calendar.prototype.getTodaysEvents = function() {
        var now;
        return (this[(now = new Date()).getDate().pad(2) + "/" + (now.getMonth() + 1).pad(2)] || []);
      };
    
      Calendar.prototype.toString = function() {
        var op = "";
        for(var i in this) {
          if(!i.isDMString()) continue;
          op += "\n" + i + ": " + this[i].join(", ");
        }
        return op;
      };
    
      // NOTE: DD/MM format.  I'm a Brit. :-P
      var cal = new Calendar(
        "02/01", "Happy Birthday to John",
        "06/01", "Happy Birthday to Max", "Happy Birthday to Jill",
        "12/01", "Happy Birthday to Trisha",
        "22/01", "Happy Birthday to Hannah",
        "26/01", "Happy Birthday to Miriam",
        "30/01", "Tomorrow is the last day to submit your assignment."
      );
    
      document.write(cal.getTodaysEvents().join("<br>"));
    </script>
    You can include <span> or (shudder) <font> tags just as you would in plain HTML. Just remember to escape quotes; for example,
    Code:
    <span style="color:blue;">Happy Birthday to John</span>
    becomes:
    Code:
    "<span style=\"color:blue;\">Happy Birthday to John</span>"
    Wow, you are really a mad but brilliant professor!!! Thanks a lot.
    I tried to customised the font type using the guidelines that you give, but i can't get it working.

    I tried to make the fonts of the birthday greetings in "blue" and in "arial" using the following codes but it failed to display:

    <span style=\"color:blue;\font:arial, tahoma;\">Happy Birthday to Trisha</span>

    What's wrong with my script above?

  6. #6
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    I think you mean:
    Code:
    <span style=\"color:blue;font-face:arial, tahoma, sans-serif;\">Happy Birthday to Trisha</span>
    Wow, you are really a mad but brilliant professor!!!
    Well, one third right
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

  7. #7
    Join Date
    Aug 2006
    Posts
    34
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Quote Originally Posted by Twey
    I think you mean:
    Code:
    <span style=\"color:blue;font-face:arial, tahoma, sans-serif;\">Happy Birthday to Trisha</span>
    Well, one third right
    I tried to use the scripts that you give but the birthday greetings were still displayed in Times Roman font, and not arial or tahoma. What could be the problem?

  8. #8
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    D'oh. The property is font-family, not font face.
    Code:
    <span style=\"color:blue;font-family:arial, tahoma, sans-serif;\">Happy Birthday to Trisha</span>
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

  9. #9
    Join Date
    Jul 2006
    Location
    Canada
    Posts
    2,581
    Thanks
    13
    Thanked 28 Times in 28 Posts

    Default

    Yeah, I tend to do that too

    I doesn't make much sense though.. The tag <font>, you'd think would have the same property as in css, in this case "family". But instead, they decide to make it annoying, and change it to "face".
    - Mike

  10. #10
    Join Date
    Aug 2006
    Posts
    34
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Quote Originally Posted by Twey
    D'oh. The property is font-family, not font face.
    Code:
    <span style=\"color:blue;font-family:arial, tahoma, sans-serif;\">Happy Birthday to Trisha</span>
    The script is working perfectly now. Thanks Prof!!!

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
  •