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.

Recommended Answers

All 6 Replies

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.

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);

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" ;

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

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.

Member Avatar

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.

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.

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 = [

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=''

displayBdayList(new Date());
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, learning, and sharing knowledge.