/    Sign up×
Community /Pin to ProfileBookmark

javascript that shows birthdays

I’m looking for some javascript code that shows whose birthday is every day.
Something that tells me: “today is [xxx’s] birthday”
where I can set a person’s name for each day of the year.
Is it too difficult to make? Because I couldn’t find anything like that, other than complete calendars where the user has to pick the day or something. I only need it to tell whose birthday is today.

to post a comment
JavaScript

15 Comments(s)

Copy linkTweet thisAlerts:
@CharlesNov 13.2006 — [code=html]<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Example</title>

<script type="text/javascript">

Date.prototype.getIndex = function () {return 'jan', 'feb', 'mar', 'apr', 'may', 'jun', 'jul', 'aug', 'sep', 'oct', 'nov', 'dec'][this.getMonth()] + this.getDate()}

birthDays = {may9: 'Charles'', nov13: 'Joe Blow's'}

if (bd = birthDays [new Date ().getIndex()]) document.write ('<p>Today is ', bd, ' birthday</p>')

</script>[/code]
Copy linkTweet thisAlerts:
@patr1c1aauthorNov 13.2006 — thanks so much! that's very helpful.
Copy linkTweet thisAlerts:
@patr1c1aauthorNov 13.2006 — sorry to bother you again, but I paste the code in the <body> part and it doesn't show anything when I load the page. Maybe there's an error in the code or am I making some mistake?
Copy linkTweet thisAlerts:
@CharlesNov 13.2006 — Please post the URL to your page so I can see what's going on. And it would be helpful to know what time zone you are in.
Copy linkTweet thisAlerts:
@patr1c1aauthorNov 13.2006 — I still didn't put the code in my webpage, but I tried making a whole new html document and inserting the code in the <head> </head> and then in the <body></body> sections but nothing happened, the page showed blank. I'm in Argentina, it's GMT -3 zone.
Copy linkTweet thisAlerts:
@CharlesNov 13.2006 — What happens when you cut and paste my example [i]exactly[/i]?
Copy linkTweet thisAlerts:
@patr1c1aauthorNov 13.2006 — I did that, I selected the entire code and pasted it into a new blank html file and didn't work.

Then I tried deleting the part where it says <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"

"http://www.w3.org/TR/html4/strict.dtd">

<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">

<title>Example</title>

and just pasted from

<script type="text/javascript"> until the </script> tag

But none of that worked. When I load the page into the web browser it shows nothing, just blank.
Copy linkTweet thisAlerts:
@CharlesNov 13.2006 — That's odd, because it works for me.
Copy linkTweet thisAlerts:
@UltimaterNov 14.2006 — Nothing will show if it is nobody's birthday in your timezone.

Sure it was nov13 in your timezone when you ran the code?

If not, then change the blue text to the date in your timezone so that it will be someone's birthday at the time you run the code.
<i>
</i>birthDays = {may9: 'Charles'', [color=blue]nov13[/color]: 'Joe Blow's'}


Otherwise I think the problem is that you copied his code and it got corrupted along the way.

i.e. the forum's [color=blue][[/color][color=blue]HTML[/color][color=blue]][/color] BBCode tag that he used to color his code on the forums didn't preserve newlines through copying and pasting.

That is why I stick with the forum's [color=blue][[/color][color=blue]CODE[/color][color=blue]][/color] BBCode tag which preserves newlines like it should.

Here is the same code Charles posted except this time using the forum's CODE tag. Try copying and pasting from here:
<i>
</i>&lt;!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd"&gt;
&lt;meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"&gt;
&lt;title&gt;Example&lt;/title&gt;

&lt;script type="text/javascript"&gt;

Date.prototype.getIndex = function () {return 'jan', 'feb', 'mar', 'apr', 'may', 'jun', 'jul', 'aug', 'sep', 'oct', 'nov', 'dec'][this.getMonth()] + this.getDate()}

birthDays = {may9: 'Charles'', nov13: 'Joe Blow's'}

if (bd = birthDays [new Date ().getIndex()]) document.write ('&lt;p&gt;Today is ', bd, ' birthday&lt;/p&gt;')

&lt;/script&gt;
Copy linkTweet thisAlerts:
@patr1c1aauthorNov 14.2006 — thanks a lot for all your help. Still, I checked my computer clock said it's 14th november, then I set one of the birthdays to 14th november instead of nov13 and it still shows me nothing. I tried it on a new html file and uploaded it so I can show you what I get when I try to use the code. The file is here:

http://tierramediauo.awardspace.com/birthdays.htm

thanks again and sorry for making this so long ?
Copy linkTweet thisAlerts:
@CharlesNov 14.2006 — But you haven't copied my example exactly. You've inserted some optional tags but you have them out of order. I can't say for sure that's the problem but it is the first thing to try.
Copy linkTweet thisAlerts:
@patr1c1aauthorNov 14.2006 — i only added the </head> tag since your code has the <title></title> tags, but anyway, still copying the exact code it returns nothing ?
Copy linkTweet thisAlerts:
@Typhoon101Nov 14.2006 — I think i may have the solution. There is an opening square bracket missing.

Date.prototype.getIndex = function () {return [B][COLOR=Red][[/COLOR][/B]'jan', 'feb'.......

Add that and it should work.
Copy linkTweet thisAlerts:
@UltimaterNov 14.2006 — You miscopied the Date.prototype.getIndex line. Between return and 'jan' there should be an opening bracket.

Edit:

You found it.
Copy linkTweet thisAlerts:
@patr1c1aauthorNov 14.2006 — yay! that was the mistake! thanks a lot, and thanks charles for your script =)
×

Success!

Help @patr1c1a spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.18,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...