0

If anyone is able to help, I'd like to create a single-line text on my site that says "Happy birthday to Samantha" whenever it's her birthday, or whenever it's another kid in my program's birthday. Including the capacity for multiple birthdays on the same day (comma spaced), the date, and/or how old they are would be icing on the cake (no pun intended); but I wouldn't mind just something basic. On days without birthdays, I'd like for the space to be blank.

Any help would be greatly appreciated. I've searched Google, and the best I could find was this page that does celebrity birthdays: http://www.netogram.com/whosbirthday/ --- I couldn't figure it out with the source code. My guess is they used php. I don't have the capacity or knowledge for php, so I was wondering if this could be done with straight javascript. Thanks for the help either way.

I have about 100 kids in my basketball program, and displaying birthdays on the site has been a big request. I suck at coding; so this is where I turn to. Hope I don't offend anyone by asking. Have a great day.

3
Contributors
6
Replies
21
Views
3 Years
Discussion Span
Last Post by jonsan32
1

You can do this with JavaScript. However, you have to store the birthday information somewhere. You could store it in JSON format within your script, in an array? or you can pull the information from the server using Ajax so you could maintain the birthday info in a database table.

Where is this birthday info and how do you plan on maintaining/updating it?

Regardless if you do this client side or server side (with PHP or other scripting language), what you need to do is... when the page is loaded, get today;s date, then search your birthday list/records and see if there is one or more that match, then display your results.

0

Thanks for the reply!

I was thinking to update it by hand within an array. I know that's hard work, but it's not so many kids. I'm already doing this on another site for holidays with a script you and some others helped me with a while back. Could I maybe tweak that script to have it display just the dates?

I'm one hell of a copy and paster and inserter, but I have no clue where to even start when it comes to constructing this stuff. If I can get 2 dates that work within an array, I can create a million more. I'm just not a code genius like you guys are.

Here's what I have below: (I'd just need text instead of images, no?)

<script type="text/javascript">
function H(){
var s=new Date();

var isMLK=
(s.getMonth()==0 && s.getDate()>14) &&
(s.getMonth()==0 && s.getDate()<22);

var isGroundhog=
(s.getMonth()==1 && s.getDate()>1) &&
(s.getMonth()==1 && s.getDate()<3);

var isValentines=
(s.getMonth()==1 && s.getDate()>12) &&
(s.getMonth()==1 && s.getDate()<15);

var isPresidents=
(s.getMonth()==1 && s.getDate()>15) &&
(s.getMonth()==1 && s.getDate()<22);

var isStpaddys=
(s.getMonth()==2 && s.getDate()>16) &&
(s.getMonth()==2 && s.getDate()<18);

var isfourth=
(s.getMonth()==6 && s.getDate()>2) &&
(s.getMonth()==6 && s.getDate()<5);

var isLabor=
(s.getMonth()==8 && s.getDate()>1) &&
(s.getMonth()==8 && s.getDate()<12);

var isHalloween=
(s.getMonth()==9 && s.getDate()>27) &&
(s.getMonth()==9 && s.getDate()<=31) ||
(s.getMonth()==10 && s.getDate()<2);

var isFools=
(s.getMonth()==3 && s.getDate()>2) &&
(s.getMonth()==3 && s.getDate()<=1) ||
(s.getMonth()==2 && s.getDate()>30);

var isveterans=
(s.getMonth()==10 && s.getDate()>10) &&
(s.getMonth()==10 && s.getDate()<12);

var isthanksgiving=
(s.getMonth()==10 && s.getDate()>21) &&
(s.getMonth()==10 && s.getDate()<28);

var isPearl=
(s.getMonth()==11 && s.getDate()>5) &&
(s.getMonth()==11 && s.getDate()<8);

var isXmas=
(s.getMonth()==11 && s.getDate()>8) &&
(s.getMonth()==11 && s.getDate()<28);

var isNewYear=
(s.getMonth()==11 && s.getDate()>30) &&
(s.getMonth()==11 && s.getDate()>=31) ||
(s.getMonth()==0 && s.getDate()<3);

document.images["seasonal"].src=
isNewYear?"https://dl.dropboxusercontent.com/u/5739741/jam%20mascot/new%20years.jpg":isMLK?"https://dl.dropboxusercontent.com/u/5739741/jam%20mascot/mlk.jpg":isGroundhog?"https://dl.dropboxusercontent.com/u/5739741/jam%20mascot/groundhog.jpg":isValentines?"https://dl.dropboxusercontent.com/u/5739741/jam%20mascot/vday.png":isPresidents?"https://dl.dropboxusercontent.com/u/5739741/jam%20mascot/usa.jpg":isStpaddys?"https://dl.dropboxusercontent.com/u/5739741/jam%20mascot/stpaddys.png"isFools?"https://dl.dropboxusercontent.com/u/5739741/jam%20mascot/april.jpg":isfourth?"https://dl.dropboxusercontent.com/u/5739741/jam%20mascot/usa.jpg":isLabor?"https://dl.dropboxusercontent.com/u/5739741/jam%20mascot/usa.jpg":isveterans?"https://dl.dropboxusercontent.com/u/5739741/jam%20mascot/usa.jpg":isHalloween?"https://dl.dropboxusercontent.com/u/5739741/jam%20mascot/halloween.jpg":isthanksgiving?"https://dl.dropboxusercontent.com/u/5739741/jam%20mascot/turkeyday.jpg":isPearl?"https://dl.dropboxusercontent.com/u/5739741/jam%20mascot/Pearl.png":isXmas?"https://dl.dropboxusercontent.com/u/5739741/jam%20mascot/xmas.jpg":"https://dl.dropboxusercontent.com/u/5739741/jam%20mascot/blank.png" ;
}
onload=H;
</script>

<img src="https://dl.dropboxusercontent.com/u/5739741/jam%20mascot/blank.png" name="seasonal" class="mascot"/>
0

And yes... I realize having all the info displayed like that will be ugly and robust, but I don't mind and it's all I currently know.

0

It might be easier to create a hash map in javascript with the date as the key. Either way the date needs to link to the birthday or birthdays.

Personally, I wouldn't ever do this clientside. It screams server side but if needs be... needs be.

0

Do any of you have a phrase I can google to perhaps find a tutorial on how to do this javascript style with all the code out in the open? Or maybe like a hint of a piece of code?

I do appreciate the replies.

0

I think I've found it. If anyone feels like sharpening this up a bit, feel free. I'd still like multiple birthdays on the same day to be on the same line and comma-separated. And I'd also like for it to say Joe's 23rd birthday rather than Joe's birthday (23) ---- Seems a bit hard with the st/rd difference in numerals.

Thanks guys!

<script language="JavaScript">

var arrBday = [
['Bob','3/24/1973'],
['John','3/24/1993'],
['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+='Happy Birthday to '+arrBday[i][0]+"!! ("+(today.getFullYear()-bday.getFullYear())+")<br>";
  }
  if (strList=='') strList=''
  document.write(strList)
}

displayBdayList(new Date());
</script>
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.