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.
Page 1 of 4 123 ... LastLast
Results 1 to 15 of 48

Thread: Birthday Script

  1. #1
    New Coder
    Join Date
    Aug 2003
    Posts
    16
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Birthday Script

    This script determins the current date, and if that date is someones birthday (from a list of birthdays, names and dates) It prints a customisable message.
    (different message for eagh entry if you want!)

    It's a very simple script but it works well. Put it between HTML tags to change the output text apperance.

    Here is the script:

    <script language="JavaScript">

    var date=new Date()
    var year=date.getYear()
    if (year < 1000)
    year+=1900
    var day=date.getDay()
    var month=date.getMonth()
    var daym=date.getDate()

    //Birthday List
    if ((month = 9) && (date = 21)) document.write("somebody's birthday");

    </script>

    //to add more that one entry, just copy the first and paste it back into the script, changing the contents

    Please tell me what you think of the script. It's free to use, but if you do use it please let me know.

    WF.

  • #2
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    11,050
    Thanks
    0
    Thanked 251 Times in 247 Posts
    Well, how about this:

    Code:
    <script language="JavaScript">
    
    var arrBday = [
    ['Bob','11/23/1973'],
    ['Peter','9/22/1977'],
    ['John','9/22/1999']
    ];
    
    function displayBdayList(today){
      var bday,strList='';
      for (var i=0;i<arrBday.length;i++){
        bday = new Date(arrBday[i][1]);
        if (!isNaN(bday) && bday.getMonth()==today.getMonth() && bday.getDate()==today.getDate()) 
    	strList+='- '+arrBday[i][0]+" ("+(today.getFullYear()-bday.getFullYear())+")<br>";
      }
      if (strList=='') strList='- NONE'
      document.write("<h4>Today's Birtdays:</h4>"+strList)
    }
    
    displayBdayList(new Date());
    </script>

  • #3
    New Coder
    Join Date
    Aug 2003
    Posts
    16
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Isuppose that my script could be used for anything - From birthdays to when payment is due for something like a subscription for some service for example.

    Nice script Glenn, musch better than mine!

    slight modification:


    <script language="JavaScript">

    var date=new Date()
    var year=date.getYear()
    if (year < 1000)
    year+=1900
    var day=date.getDay()
    var month=date.getMonth()
    var daym=date.getDate()

    //Birthday List
    if ((month = 9) && (date = 21)) window.alert("Please wish somebody a Happy Birthday");

    </script>
    Last edited by WelshFlyer; 09-22-2003 at 07:32 PM.

  • #4
    New to the CF scene
    Join Date
    Aug 2005
    Location
    Bristol, England
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts
    hi there

    i really like Glens birthday script and would like to use it. I just wandered if it is possible to display peoples birthdays falling in the next 2 weeks (14 days) instead of just on todays date.

    and also i would like to to display the birthdays in a horizontal comma separated row instead of a vertical list, can anyone help with that please.

    your help would be very much appreciated!

    many thanks, nathan.

    Code:
    <script language="JavaScript">
    
    var arrBday = [
    ['Bob','11/23/1973'],
    ['Peter','9/22/1977'],
    ['John','9/22/1999']
    ];
    
    function displayBdayList(today){
    var bday,strList='';
    for (var i=0;i<arrBday.length;i++){
    bday = new Date(arrBday[i][1]);
    if (!isNaN(bday) && bday.getMonth()==today.getMonth() && bday.getDate()==today.getDate()) 
    strList+='- '+arrBday[i][0]+" ("+(today.getFullYear()-bday.getFullYear())+")<br>";
    }
    if (strList=='') strList='- NONE'
    document.write("<h4>Today's Birtdays:</h4>"+strList)
    }
    
    displayBdayList(new Date());
    </script>

  • #5
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    11,050
    Thanks
    0
    Thanked 251 Times in 247 Posts
    Code:
    <html>
    <head>
    <title>Birthday List</title>
    <script type="text/javascript">
    Date.prototype.getDiff = function(date, interval){
      if (typeof date == "string"){
         date = new Date(date);
      }
      if (isNaN(date) || !(date instanceof Date)){
         return NaN; //invalid date passed
      }
      if (typeof interval == "undefined") interval = "ms"; //msec (default)
      var diff = this - date; //alert(this+' - '+date+" = "+diff)//diff in msec
      switch(interval.toLowerCase()){
        case "s": //sec
          diff = diff/1000; break;
        case "n": //min
          diff = diff/(1000*60); break;
        case "h": //hr
          diff = diff/(1000*60*60); break;
        case "d": //day
          diff = diff/(1000*60*60*24); break;
        case "m": //month
          diff = diff/(1000*60*60*24*30); break;
        case "y": //year
          diff = diff/(1000*60*60*24*365); break;
        default:
          ; //msec
      }
      return Math.floor(diff);
    }
    
    var arrBday = [
      ['Bob','7/23/1973'],
      ['Glenn','8/4/1989'],
      ['Nathan','8/11/1999'],
      ['Peter','8/18/1977'],
      ['John','8/19/1999']
    ];
    
    function getBdayList(numDays){
      var bday,temp,idx,diff;
      var today = new Date();
      var bdayList = new Array();  
      for (var i=0;i<arrBday.length;i++){
        bday = new Date(arrBday[i][1]);
        if (isNaN(bday)) continue;
        temp = new Date(today.getFullYear(), bday.getMonth(), bday.getDate(), 23, 59, 59, 999);
        diff = temp.getDiff(today, "d");
        if (diff >= 0 && diff <= numDays){
           idx = bdayList.length;
           bdayList[idx] = new Object();
           bdayList[idx].name = arrBday[i][0];
           bdayList[idx].bday = arrBday[i][1];
           bdayList[idx].age = today.getDiff(bday, "y");       
           if (diff > 0) bdayList[idx].age = bdayList[idx].age + 1;
        }
      }
      return bdayList;    
    }
    
    function displayBdayList(){
      var bdayList = getBdayList(14);
      var len = bdayList.length;
      var s = "";
      if (len>0){
        for (var i=0; i<len; i++){
           if (s != ""){
              s += ", " + bdayList[i].name + " - " + bdayList[i].bday + " (" + bdayList[i].age + ")";
           }
           else{
              s = bdayList[i].name + " - " + bdayList[i].bday + " (" + bdayList[i].age + ")";
           }     
         }
      }
      else{
        s = "No birthdays.";
      }
      document.write(s);
    }
    </script>
    </head>
    <body>
    <h1>Birthday Celebrants</h1>
    <script type="text/javascript">
    displayBdayList();
    </script>
    </body>
    </html>

  • #6
    New to the CF scene
    Join Date
    Aug 2005
    Location
    Bristol, England
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts
    many thanks Glen.

    its looking great. i prefererd it without displaying the actual birthdate and managed to remove that.

    is it possible so that the name of a person has a hyperlink to it.

    Code:
    var arrBday = [
      ['Bob'<a href=http://www.bob.co.uk>,'8/11/1973'],
      ['Nathan<a href=http://www.nathy.co.uk>','08/06/1983'], 
      ['Glen<a href=http://www.glen.co.uk>','8/11/1999'], 
    ]
    when i try and do this it doesnt hyperlink the names properly. it would be great if it could hyperlink the name and age eg: Nathan - (6)


    and one final query, would it be possible to have a person with a birthday actually today displayed above the list of persons within the next 14 days. if thats too complicated no problem.

    eg

    Birthday Celebrants
    Today Michael (15)
    Within next 14 days Glenn - 8/4/1989 (16), Nathan - 8/11/1999 (6), Peter - 8/18/1977 (28)

    many thanks, nathan.

  • #7
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    11,050
    Thanks
    0
    Thanked 251 Times in 247 Posts
    Code:
    <html>
    <head>
    <title>Birthday List</title>
    <style type="text/css">
    .header {
      font-weight: bold;  
    }
    </style>
    <script type="text/javascript">
    Date.prototype.getDiff = function(date, interval){
      if (typeof date == "string"){
         date = new Date(date);
      }
      if (isNaN(date) || !(date instanceof Date)){
         return NaN; //invalid date passed
      }
      if (typeof interval == "undefined") interval = "ms"; //msec (default)
      var diff = this - date; //alert(this+' - '+date+" = "+diff)//diff in msec
      switch(interval.toLowerCase()){
        case "s": //sec
          diff = diff/1000; break;
        case "n": //min
          diff = diff/(1000*60); break;
        case "h": //hr
          diff = diff/(1000*60*60); break;
        case "d": //day
          diff = diff/(1000*60*60*24); break;
        case "m": //month
          diff = diff/(1000*60*60*24*30); break;
        case "y": //year
          diff = diff/(1000*60*60*24*365); break;
        default:
          ; //msec
      }
      return Math.floor(diff);
    }
    
    var arrBday = [
      ['Bob', '7/23/1973', "http://www.bob.co.uk"],
      ['Glenn', '8/5/1989', "http://www.glenn.co.uk"],
      ['Nathan', '8/5/1999', "http://www.nathan.co.uk"],
      ['Peter', '8/18/1977', "http://www.peter.co.uk"],
      ['John', '8/19/1999', "http://www.john.co.uk"]
    ];
    
    function getBdayList(numDays){
      var bday,temp,idx,diff;
      var today = new Date();
      var bdayList = new Array();  
      for (var i=0;i<arrBday.length;i++){
        bday = new Date(arrBday[i][1]);
        if (isNaN(bday)) continue;
        temp = new Date(today.getFullYear(), bday.getMonth(), bday.getDate(), 23, 59, 59, 999);
        diff = temp.getDiff(today, "d");
        if (diff >= 0 && diff <= numDays){
           idx = bdayList.length;
           bdayList[idx] = new Object();
           bdayList[idx].name = arrBday[i][0];
           bdayList[idx].bday = arrBday[i][1];
           bdayList[idx].age = today.getDiff(bday, "y");       
           if (diff > 0) bdayList[idx].age = bdayList[idx].age + 1;
           bdayList[idx].today = (diff == 0) ? true : false;
           bdayList[idx].site = arrBday[i][2];
        }
      }
      return bdayList;    
    }
    
    function displayBdayList(){
      var bdayList = getBdayList(14);
      var len = bdayList.length;
      var s1 = ""; //today's bday list
      var s2 = ""; //next 2 week's bday list
      if (len>0){
        for (var i=0; i<len; i++){
           if (bdayList[i].today){
              if (s1 != ""){
                 s1 += ', <a href="' + bdayList[i].site + '">' +  bdayList[i].name + ' (' + bdayList[i].age + ')</a>';
              }
              else{
                 s1 = '<span class="header">Today</span> <a href="' + bdayList[i].site + '">' +  bdayList[i].name + ' (' + bdayList[i].age + ')</a>';
              }  
           }
           else{
             if (s2 != ""){
                s2 += ', <a href="' + bdayList[i].site + '">' +  bdayList[i].name + ' - ' + bdayList[i].bday + ' (' + bdayList[i].age + ')</a>';
             }
             else{
                s2 = '<span class="header">Within next 14 days</span> <a href="' + bdayList[i].site + '">' +  bdayList[i].name + ' - ' + bdayList[i].bday + ' (' + bdayList[i].age + ')</a>';
             }     
           }
         }
      }
      else{
        s1 = "No birthdays.";
      }
      document.write('<div>' + s1 + '</div><div>' + s2 + '</div>');
    }
    </script>
    </head>
    <body>
    <h1>Birthday Celebrants</h1>
      <div>
        <script type="text/javascript">
          displayBdayList();
        </script>
      </div>
    </body>
    </html>

  • #8
    New to the CF scene
    Join Date
    Aug 2005
    Location
    Breda, Netherlands
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Exclamation

    sorry wrong place for a question....
    moved to http://www.codingforums.com/showthre...746#post349746
    Last edited by 1of6Billion; 08-28-2005 at 01:31 PM. Reason: add topic url

  • #9
    New to the CF scene
    Join Date
    Aug 2005
    Location
    Bristol, England
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Code:
    <script type="text/javascript">
    Date.prototype.getDiff = function(date, interval){
      if (typeof date == "string"){
         date = new Date(date);
      }
      if (isNaN(date) || !(date instanceof Date)){
         return NaN; //invalid date passed
      }
      if (typeof interval == "undefined") interval = "ms"; //msec (default)
      var diff = this - date; //alert(this+' - '+date+" = "+diff)//diff in msec
      switch(interval.toLowerCase()){
        case "s": //sec
          diff = diff/1000; break;
        case "n": //min
          diff = diff/(1000*60); break;
        case "h": //hr
          diff = diff/(1000*60*60); break;
        case "d": //day
          diff = diff/(1000*60*60*24); break;
        case "m": //month
          diff = diff/(1000*60*60*24*30); break;
        case "y": //year
          diff = diff/(1000*60*60*24*365); break;
        default:
          ; //msec
      }
      return Math.floor(diff);
    }
    
    var arrBday = [
      ['nathan', '5/2/1983', "http://www.nathy.co.uk/forum/profile.php?mode=viewprofile&u=5"],
      ['Crispy Dave', '4/23/1985', "http://www.nathy.co.uk/forum/profile.php?mode=viewprofile&u=6"],
      ['Snuggs', '10/30/1984', "http://www.nathy.co.uk/forum/profile.php?mode=viewprofile&u=7"],
      ['LizzieKitten', '5/1/1985', "http://www.nathy.co.uk/forum/profile.php?mode=viewprofile&u=8"],
      ['salimander', '1/7/1984', "http://www.nathy.co.uk/forum/profile.php?mode=viewprofile&u=9"],
      ['Farmer Phil', '10/24/1984', "http://www.nathy.co.uk/forum/profile.php?mode=viewprofile&u=10"],
      ['Andy', '8/30/1985', "http://www.nathy.co.uk/forum/profile.php?mode=viewprofile&u=12"],
      ['Becky', '2/24/1984', "http://www.nathy.co.uk/forum/profile.php?mode=viewprofile&u=11"],
      ['Rach', '8/19/1986', "http://www.nathy.co.uk/forum/profile.php?mode=viewprofile&u=13"],
      ['mandy', '7/12/1984', "http://www.nathy.co.uk/forum/profile.php?mode=viewprofile&u=14"],
      ['sarah', '1/20/1984', "http://www.nathy.co.uk/forum/profile.php?mode=viewprofile&u=15"],
      ['Tom', '4/12/1984', "http://www.nathy.co.uk/forum/profile.php?mode=viewprofile&u=17"],
      ['JonnyG', '1/29/1986', "http://www.nathy.co.uk/forum/profile.php?mode=viewprofile&u=20"],
      ['benny', '4/11/1985', "http://www.nathy.co.uk/forum/profile.php?mode=viewprofile&u=22"],
      ['Nicnic', '2/25/1985', "http://www.nathy.co.uk/forum/profile.php?mode=viewprofile&u=27"],
      ['Beth!', '8/7/1981', "http://www.nathy.co.uk/forum/profile.php?mode=viewprofile&u=28"],
      ['Danny', '5/14/1986', "http://www.nathy.co.uk/forum/profile.php?mode=viewprofile&u=29"],
      ['Hannah', '8/10/1984', "http://www.nathy.co.uk/forum/profile.php?mode=viewprofile&u=30"],
      ['rec', '9/13/1984', "http://www.nathy.co.uk/forum/profile.php?mode=viewprofile&u=31"],
      ['Luke', '6/14/1983', "http://www.nathy.co.uk/forum/profile.php?mode=viewprofile&u=32"],
      ['Lil Franny', '4/5/1985', "http://www.nathy.co.uk/forum/profile.php?mode=viewprofile&u=34"],
      ['Catus', '4/09/1985', "http://www.nathy.co.uk/forum/profile.php?mode=viewprofile&u=35"],
      ['Kay', '7/22/1984', "http://www.nathy.co.uk/forum/profile.php?mode=viewprofile&u=36"],
      ['shing', '2/26/1985', "http://www.nathy.co.uk/forum/profile.php?mode=viewprofile&u=37"],
      ['Toad in the Soul', '8/3/1984', "http://www.nathy.co.uk/forum/profile.php?mode=viewprofile&u=40"],
      ['Emily', '7/30/1984', "http://www.nathy.co.uk/forum/profile.php?mode=viewprofile&u=41"],
      ['Rachx', '12/10/1984', "http://www.nathy.co.uk/forum/profile.php?mode=viewprofile&u=43"],
      ['Wrighty', '5/15/1983', "http://www.nathy.co.uk/forum/profile.php?mode=viewprofile&u=44"],
      ['ZsaZsa Bates', '4/18/1985', "http://www.nathy.co.uk/forum/profile.php?mode=viewprofile&u=45"],
      ['siani', '12/13/1982', "http://www.nathy.co.uk/forum/profile.php?mode=viewprofile&u=47"],
      ['sam', '10/30/1984', "http://www.nathy.co.uk/forum/profile.php?mode=viewprofile&u=48"],
      ['DEREK', '4/13/1986', "http://www.nathy.co.uk/forum/profile.php?mode=viewprofile&u=49"],
      ['Erad', '6/8/1986', "http://www.nathy.co.uk/forum/profile.php?mode=viewprofile&u=51"],
      ['rachj', '6/26/1986', "http://www.nathy.co.uk/forum/profile.php?mode=viewprofile&u=52"],
      ['eot2', '12/2/1978', "http://www.nathy.co.uk/forum/profile.php?mode=viewprofile&u=55"],
      ['olop1986', '4/29/1986', "http://www.nathy.co.uk/forum/profile.php?mode=viewprofile&u=56"],
      ['Aberads', '7/14/1984', "http://www.nathy.co.uk/forum/profile.php?mode=viewprofile&u=57"],
      ['chloe', '3/13/1986', "http://www.nathy.co.uk/forum/profile.php?mode=viewprofile&u=59"],
      ['Freddie', '8/20/1985', "http://www.nathy.co.uk/forum/profile.php?mode=viewprofile&u=60"],
      ['smeloise', '11/27/1985', "http://www.nathy.co.uk/forum/profile.php?mode=viewprofile&u=61"],
      ['Serena', '10/17/1984', "http://www.nathy.co.uk/forum/profile.php?mode=viewprofile&u=62"],
      ['Richard', '4/7/1982', "http://www.nathy.co.uk/forum/profile.php?mode=viewprofile&u=63"],
      ['llion_evans', '1/5/1984', "http://www.nathy.co.uk/forum/profile.php?mode=viewprofile&u=64"],
      ['jo', '6/3/1986', "http://www.nathy.co.uk/forum/profile.php?mode=viewprofile&u=65"],
      ['Holly', '2/14/1986', "http://www.nathy.co.uk/forum/profile.php?mode=viewprofile&u=66"],
      ['reuben', '10/21/1985', "http://www.nathy.co.uk/forum/profile.php?mode=viewprofile&u=70"],
      ['Poppy', '3/7/1985', "http://www.nathy.co.uk/forum/profile.php?mode=viewprofile&u=72"],
      ['Ben', '10/30/1984', "http://www.nathy.co.uk/forum/profile.php?mode=viewprofile&u=77"],
      ['Sam R', '12/4/1984', "http://www.nathy.co.uk/forum/profile.php?mode=viewprofile&u=80"],
      ['Kevolution', '10/30/1985', "http://www.nathy.co.uk/forum/profile.php?mode=viewprofile&u=83"],
      ['crazychrist', '7/20/1986', "http://www.nathy.co.uk/forum/profile.php?mode=viewprofile&u=86"],
      ['alunjevans', '8/8/1986', "http://www.nathy.co.uk/forum/profile.php?mode=viewprofile&u=88"],
      ['smyrell', '12/9/1985', "http://www.nathy.co.uk/forum/profile.php?mode=viewprofile&u=90"],
      ['gtanswell', '11/9/1984', "http://www.nathy.co.uk/forum/profile.php?mode=viewprofile&u=91"],
      ['Mark Llanbadarn', '4/27/1986', "http://www.nathy.co.uk/forum/profile.php?mode=viewprofile&u=94"],
      ['jym1', '10/7/1982', "http://www.nathy.co.uk/forum/profile.php?mode=viewprofile&u=95"],
      ['Pink_Jelly', '7/7/1987', "http://www.nathy.co.uk/forum/profile.php?mode=viewprofile&u=96"],
      ['joy', '12/14/1983', "http://www.nathy.co.uk/forum/profile.php?mode=viewprofile&u=99"],
      ['Beth Harrison', '3/13/1986', "http://www.nathy.co.uk/forum/profile.php?mode=viewprofile&u=102"],
      ['Little Miss Organized', '1/10/1986', "http://www.nathy.co.uk/forum/profile.php?mode=viewprofile&u=103"],
      ['Dave Smyrell', '12/9/1985', "http://www.nathy.co.uk/forum/profile.php?mode=viewprofile&u=104"],
      ['TomJ', '11/11/1985', "http://www.nathy.co.uk/forum/profile.php?mode=viewprofile&u=105"],
      ['Rhys Llwyd', '7/2/1985', "http://www.nathy.co.uk/forum/profile.php?mode=viewprofile&u=108"],
      ['Rosie', '7/2/1985', "http://www.nathy.co.uk/forum/profile.php?mode=viewprofile&u=110"],
      ['amk4', '9/25/1984', "http://www.nathy.co.uk/forum/profile.php?mode=viewprofile&u=111"],
      ['colin ailes', '7/20/1985', "http://www.nathy.co.uk/forum/profile.php?mode=viewprofile&u=112"],
      ['Jase', '2/9/1986', "http://www.nathy.co.uk/forum/profile.php?mode=viewprofile&u=114"],
      ['mla4', '7/29/1985', "http://www.nathy.co.uk/forum/profile.php?mode=viewprofile&u=113"],
      ['amy', '11/19/1984', "http://www.nathy.co.uk/forum/profile.php?mode=viewprofile&u=115"],
      ['bethan', '3/18/1984', "http://www.nathy.co.uk/forum/profile.php?mode=viewprofile&u=119"],
      ['steve ellis', '8/29/1987', "http://www.nathy.co.uk/forum/profile.php?mode=viewprofile&u=120"],
      ['helen', '8/24/1987', "http://www.nathy.co.uk/forum/profile.php?mode=viewprofile&u=121"],
      ['James', '10/4/1984', "http://www.nathy.co.uk/forum/profile.php?mode=viewprofile&u=122"],
      ['Em', '1/28/1986', "http://www.nathy.co.uk/forum/profile.php?mode=viewprofile&u=123"],
      ['deb', '4/2/1987', "http://www.nathy.co.uk/forum/profile.php?mode=viewprofile&u=125"],
      ['wacko', '8/21/1984', "http://www.nathy.co.uk/forum/profile.php?mode=viewprofile&u=129"],
      ['Elayne', '8/22/1985', "http://www.nathy.co.uk/forum/profile.php?mode=viewprofile&u=130"],
      ['Andrew', '10/9/1982', "http://www.nathy.co.uk/forum/profile.php?mode=viewprofile&u=131"],
      ['bouncy_lil_rach', '6/5/1985', "http://www.nathy.co.uk/forum/profile.php?mode=viewprofile&u=132"],
      ['Jessica', '7/14/1986', "http://www.nathy.co.uk/forum/profile.php?mode=viewprofile&u=134"],
      ['mozzar', '8/25/1987', "http://www.nathy.co.uk/forum/profile.php?mode=viewprofile&u=137"],
      ['Alice', '8/7/1986', "http://www.nathy.co.uk/forum/profile.php?mode=viewprofile&u=138"],
      ['Darren Webster', '9/17/1986', "http://www.nathy.co.uk/forum/profile.php?mode=viewprofile&u=126"],
      ['Gemma', '11/9/1986', "http://www.nathy.co.uk/forum/profile.php?mode=viewprofile&u=161"],
      ['miniminime', '9/11/1985', "http://www.nathy.co.uk/forum/profile.php?mode=viewprofile&u=150"]
      ];
    
    function getBdayList(numDays){
      var bday,temp,idx,diff;
      var today = new Date();
      var bdayList = new Array();
      for (var i=0;i<arrBday.length;i++){
        bday = new Date(arrBday[i][1]);
        if (isNaN(bday)) continue;
        temp = new Date(today.getFullYear(), bday.getMonth(), bday.getDate(), 23, 59, 59, 999);
        diff = temp.getDiff(today, "d");
        if (diff >= 0 && diff <= numDays){
           idx = bdayList.length;
           bdayList[idx] = new Object();
           bdayList[idx].name = arrBday[i][0];
           bdayList[idx].bday = arrBday[i][1];
           bdayList[idx].age = today.getDiff(bday, "y");
           if (diff > 0) bdayList[idx].age = bdayList[idx].age + 1;
           bdayList[idx].today = (diff == 0) ? true : false;
           bdayList[idx].site = arrBday[i][2];
        }
      }
      return bdayList;
    }
    
    function displayBdayList(){
      var bdayList = getBdayList(14);
      var len = bdayList.length;
      var s1 = ""; //today's bday list
      var s2 = ""; //next 2 week's bday list
      if (len>0){
        for (var i=0; i<len; i++){
           if (bdayList[i].today){
              if (s1 != ""){
                 s1 += ', <a href="' + bdayList[i].site + '">' +  bdayList[i].name + ' (' + bdayList[i].age + ')</a>';
              }
              else{
                 s1 = '<span class="header">Today</span> <a href="' + bdayList[i].site + '">' +  bdayList[i].name + ' (' + bdayList[i].age + ')</a>';
              }
           }
           else{
             if (s2 != ""){
                s2 += ', <a href="' + bdayList[i].site + '">' +  bdayList[i].name + ' (' + bdayList[i].age + ')</a>';
             }
             else{
                s2 = '<span class="header">Within next 14 days</span> <a href="' + bdayList[i].site + '">' +  bdayList[i].name + ' (' + bdayList[i].age + ')</a>';
             }
           }
         }
      }
      else{
        s1 = "No birthdays.";
      }
      document.write('<div>' + s1 + '</div><div>' + s2 + '</div>');
    }
    </script>
    hi again glenn.

    apologies for not thanking you before for your help. i have had the birthday script running on my site now for a while.

    just one problem. often it displays the persons age incorrectly in brackets. it changes to sometimes being the correct and sometimes the wrong for no apparent reason.

    do you have any idea why this would be please?

    you can see the script in action at http://www.abercu.org.uk and by scrolling down to the bottom.

    many thanks, nathan

  • #10
    New to the CF scene
    Join Date
    Aug 2005
    Location
    Bristol, England
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts
    please can someone help me with this? ....birthdays keep displaying wrong ages in brackets.. and im not sure where the code is incorrect.

    thank you, nathan

  • #11
    Regular Coder Nischumacher's Avatar
    Join Date
    Oct 2005
    Location
    Bombay, India
    Posts
    196
    Thanks
    0
    Thanked 2 Times in 2 Posts
    just change the arrBday to the following for a while to see what happens... save the previous value...
    Code:
    var arrBday = [ ['nathan', '11/1/1983', 
    "http://www.nathy.co.uk/forum/profile.php?mode=viewprofile&u=5"], ['Crispy 
    Dave', '11/2/1983', 
    "http://www.nathy.co.uk/forum/profile.php?mode=viewprofile&u=6"], ['Snuggs', 
    '11/3/1983', "http://www.nathy.co.uk/forum/profile.php?mode=viewprofile&u=7"], 
    ['LizzieKitten', '11/4/1983', 
    "http://www.nathy.co.uk/forum/profile.php?mode=viewprofile&u=8"], ['salimander', 
    '11/5/1983', "http://www.nathy.co.uk/forum/profile.php?mode=viewprofile&u=9"], 
    ['Farmer Phil', '11/6/1983', 
    "http://www.nathy.co.uk/forum/profile.php?mode=viewprofile&u=10"], ['Andy', 
    '11/7/1983', "http://www.nathy.co.uk/forum/profile.php?mode=viewprofile&u=12"], 
    ['Becky', '11/8/1983', 
    "http://www.nathy.co.uk/forum/profile.php?mode=viewprofile&u=11"], ['Rach', 
    '11/9/1983', "http://www.nathy.co.uk/forum/profile.php?mode=viewprofile&u=13"], 
    ['mandy', '11/10/1983', 
    "http://www.nathy.co.uk/forum/profile.php?mode=viewprofile&u=14"], ['sarah', 
    '11/11/1983', "http://www.nathy.co.uk/forum/profile.php?mode=viewprofile&u=15"], 
    ['Tom', '11/12/1983', 
    "http://www.nathy.co.uk/forum/profile.php?mode=viewprofile&u=17"], ['JonnyG', 
    '11/13/1983', "http://www.nathy.co.uk/forum/profile.php?mode=viewprofile&u=20"], 
    ['benny', '11/14/1983', 
    "http://www.nathy.co.uk/forum/profile.php?mode=viewprofile&u=22"], ['Nicnic', 
    '11/15/1983', "http://www.nathy.co.uk/forum/profile.php?mode=viewprofile&u=27"], 
    ['Beth!', '11/16/1983', 
    "http://www.nathy.co.uk/forum/profile.php?mode=viewprofile&u=28"], ['Danny', 
    '11/17/1983', "http://www.nathy.co.uk/forum/profile.php?mode=viewprofile&u=29"], 
    ['Hannah', '11/18/1983', 
    "http://www.nathy.co.uk/forum/profile.php?mode=viewprofile&u=30"], ['rec', 
    '11/19/1983', "http://www.nathy.co.uk/forum/profile.php?mode=viewprofile&u=31"], 
    ['Luke', '11/20/1983', 
    "http://www.nathy.co.uk/forum/profile.php?mode=viewprofile&u=32"], ['Lil 
    Franny', '11/21/1983', 
    "http://www.nathy.co.uk/forum/profile.php?mode=viewprofile&u=34"], ['Catus', 
    '11/22/1983', "http://www.nathy.co.uk/forum/profile.php?mode=viewprofile&u=35"], 
    ['Kay', '11/23/1983', 
    "http://www.nathy.co.uk/forum/profile.php?mode=viewprofile&u=36"], ['shing', 
    '11/24/1983', "http://www.nathy.co.uk/forum/profile.php?mode=viewprofile&u=37"], 
    ['Toad in the Soul', '11/25/1983', 
    "http://www.nathy.co.uk/forum/profile.php?mode=viewprofile&u=40"], ['Emily', 
    '11/26/1983', "http://www.nathy.co.uk/forum/profile.php?mode=viewprofile&u=41"], 
    ['Rachx', '11/27/1983', 
    "http://www.nathy.co.uk/forum/profile.php?mode=viewprofile&u=43"], ['Wrighty', 
    '11/28/1983', "http://www.nathy.co.uk/forum/profile.php?mode=viewprofile&u=44"] 
    ];
    you will see that the people with their birthdays in the next 6 days are incremented by a year... why does this happen... i don't know... so until somebody comes up with the explaination and the right solution... here is mine that should work fine...

    just make this change in your displayBdayList function from
    Code:
    if (diff > 0) bdayList[idx].age = bdayList[idx].age + 1;
    to this
    Code:
    if (diff > 6) bdayList[idx].age = bdayList[idx].age + 1;
    - NS 666
    .net DEVILoper

  • #12
    New to the CF scene
    Join Date
    Aug 2005
    Location
    Bristol, England
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts
    hey NS

    thanks very much...seeems to have worked now. thanks for looking at it for me, nathan.

    ps went to India when I was 16 about 6 years ago.. wonderful country!

  • #13
    Regular Coder Nischumacher's Avatar
    Join Date
    Oct 2005
    Location
    Bombay, India
    Posts
    196
    Thanks
    0
    Thanked 2 Times in 2 Posts
    as i said... it will work... but i still maintain that it is not the best solution...
    PS : never been to england
    Last edited by Nischumacher; 11-09-2005 at 04:07 PM.
    - NS 666
    .net DEVILoper

  • #14
    New to the CF scene
    Join Date
    Nov 2005
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Is there a limit to the number of "birthday entries" these scripts can have?
    I've tried both of the basic scripts from the beginning of this thread and have placed 43 entries into each one and get script errors when I try to have it on a webpage.

  • #15
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    11,050
    Thanks
    0
    Thanked 251 Times in 247 Posts
    What error message? You probably have misplaced quotes or brackets in the birthday array definition. Run the code in Firefox to easily spot the error.


  •  
    Page 1 of 4 123 ... LastLast

    Posting Permissions

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