I wan't to be able to have a list of birthdates advance by one digit when that particular persons b-day rolls around. Is there a simple script out there that I can apply here?

Thanks in advance,
rs

No. You'll need server-side code, and a database in which to store the dates.

you always go for the server side option! which is usually the sensible option... as you don't need to assume the client will have javascript enabled.

but sometimes you can't use server side code, and sometimes you don't have a database to back your application.

in this case i'd suggest using cookies... i know, you can't expect your cookie to be there in a year... and they might not have javascript... but they will have to tell you lots about themselves in the first place... so why not ask them to turn on javascript and not delete their cookies too?

It's just a little 'ol web page, isn't there a way to say in a script...

"so and so was born on this date - and today is this date - so that makes them this age"?

I saw a script that would tell you "How long have you had that job? -or- How many days old are you?", so why can't you have one that calculates years based on a birth date and the current date?

alpha-foobar:

I don't always recommend the server-side option, but in this case, you'd have to agree, it is the most sensible approach.

The problem is the "so-and-so was born on this date". How do you know that? Where are you going to store that? With JavaScript, you'll have to store that information in a cookie, and hope that cookie is still there in a year.

So for this scenario, you'll need server-side code.

Redsaber:

Technically, you CAN have such a script. It's just basic math, which JavaScript can do. The core issue though, is to KNOW a particular person's date of birth. How do you plan on storing that? Where? You have to store it somewhere that is accesible by your code.

If by "your code" we mean "code residing on and processed by your web server", then you would store everyone's birthdays on the server. You'd either use a database, such as MySQL, or an XML file.

If by "your code" we mean, JavaScript running on the browser, then you're faced with that fact that the birthday will have to be stored on the individual user's machine. The only way to do that is via a cookie.

The problem with that is, cookies don't last. The user can decide whether or not to accept cookies in the first place, and can arbitrarily delete them. For example, on my systems, the cookies don't last beyond the current browser session. So you could "remember" my date of birth for about 5 minutes, which renders your script useless.

That's why, in my opinion, my first answer is correct: "No.", there isn't a simple script to do this, and you'll need server-side code coupled with a persistent data store.

In that script you referenced, notice that a date is being passed into the "countup" function. You have to ask yourself, where did that date come from? It's hard-coded in the example! Well, you obviously cannot hard-code each of your users' birthdays in your script. You have to PUT an individual's birtday in the script, either client-side, by retrieving from a cookie, or server-side, by retrieving it from your database.

tgreer: you do often suggest a server-side solution... which is funny because this is a client side forum. However, I agree.. if redsabre wanted a production sensible solution, this would be done server side using a database holding important peoples data. But I don't think redsabre wants a sensible solution here... i think the redsabre just wants someone to write a javascript that can be posted onto redsabre's website.

redsabre: using the javascript that you have supplied a link to, you should be able to work out how old someone is. It is easy to work out how many days old someone is from the code... it isn't such a big step to work out everything else.... and i've ended up doing it.. so here it is, based on the link you gave me.

<html>
<head>

<SCRIPT LANGUAGE="JavaScript">

<!-- This script and many more are available free online at -->
<!-- The JavaScript Source!! http://javascript.internet.com -->

<!-- Begin
var montharray=new Array("Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec");
function countup(yr,m,d) {
var today=new Date();
var todayy=today.getYear();

// Y2K Fix by Isaac Powell
// http://onyx.idbsu.edu/~ipowell

if ((navigator.appName == "Microsoft Internet Explorer") && (todayy < 2000))		
todayy="19" + todayy;
if (navigator.appName == "Netscape")
todayy=1900 + todayy;

var todaym=today.getMonth();
var todayd=today.getDate();
var todaystring=montharray[todaym]+" "+todayd+", "+todayy;
var paststring=montharray[m-1]+" "+d+", "+yr;

document.write(paststring + " <br/>");

var oldDate = new Date(paststring);

var dyears  = today.getFullYear() - oldDate.getFullYear();
var dmonths = today.getMonth() - oldDate.getMonth();
var ddays   = today.getDate() - oldDate.getDate();
var dhours  = today.getHours() - oldDate.getHours();
var dminutes= today.getMinutes() - oldDate.getMinutes();
var dseconds= today.getSeconds() - oldDate.getSeconds();
var dmillis = today.getMilliseconds() - oldDate.getMilliseconds();

if(dmillis < 0){
	dmillis += 1000;
	dseconds--;
}
if(dseconds < 0){
	dseconds += 60;
	dminutes--;
}
if(dminutes < 0){
	dminutes += 60;
	dhours--;
}
if(dhours < 0){
	dhours += 24;
	ddays--;
}
if(ddays < 0){
	// would need to get the days of the month here
	var dayMilli = 24*60*60*1000;
	var newDateString = montharray[today.getMonth()] + " 1, " + today.getFullYear();
	
	document.write(newDateString + " <br/>");
	document.write(" last day of month = " + 
		Date.parse(newDateString) + " <br/>");
		
	ddays += 
		new Date(Date.parse(newDateString) - dayMilli).getDate();	
	dmonths--;
}
if(dmonths < 0){
	dmonths += 12;
	dyears--;
}

document.write((dyears) + " Years, " +
			(dmonths) + " Months, " +
			(ddays) + " Days, " +
			(dhours) + " Hours, " +
			(dminutes) + " Minutes, " +
			(dseconds) + " Seconds, " +
			(dmillis) + " Milliseconds " +
			"old.<br/>");

}
countup(1997,8,29);  // Date in format:  (year,month,day)
//  End -->
</script>
</head>

<body>
<p><center>
<font face="arial, helvetica" size="-2">Free JavaScripts provided<br>
by <a href="http://javascriptsource.com">The JavaScript Source</a></font>
</center><p>
</body></html>

Yup, its hardcoded in there... but you could get the value from a text field or something. But this wouldn't really serve any real use... except for working out exactly how old you are... this may prove useful as i get older..

alpha_foobar: we're straying off topic, but I think the discussion has some merit, so I'll forge ahead.

I'm a web-developer (actually, an application developer who often writes web-enabled applications). Over the years I've come to the conclusion that any web application must use both server-side code and client-side code.

I've also realized that most new web developers don't understand that. Many are entering web development from the graphic design field, and so are very used to working with user interfaces. For them the natural assumption is to try to do everything via client-side code.

As a contrast, many ASP.NET developers come from traditional desktop Windows development, and so have no concept of client-side code. In fact, they often resort to (because ASP.NET encourages) the most bizzare server-side code contortions, when what they really should use is a client-side function.

So, yes, I often indeed recommend a server-side solution, because I'm not speaking from a pure theoretical "how would you do this in JavaScript" viewpoint. I try to speak from a real-world practical, "here's how to approach this" viewpoint, realizing that most posters have only a fuzzy concept of client vs. server.

It's ironic, I agree, that in the JavaScript forum you'll often see me recommending a server-side solution, while in the various ASP.NET fora, you'll find me preaching the client-side gospel.

But I don't think redsabre wants a sensible solution here... i think the redsabre just wants someone to write a javascript that can be posted onto redsabre's website.

Well, actually, I was looking for a sensible solution. Having someone write me a JS wasn't my initial intention, but I'll take whatever is offered gladly and graciously :)

I would never ask someone to create something for me that they didn't want to create just because I didn't want to do the work, but have found that most follks here (yourself included) are very helpful. It was my belief that something suited for my needs already existed and was simply looking to be pointed in that direction.

I suppose it could be called lazy or opportunistic, but I was not (nor am I now) at a place where I can spend a lot of time learning things that are already offered freely across the net. Just the same, :!:thank you:!: for the time you put in. When I next update my brother's website I plan to implement the script you have provided :) .

The hard coded solution you have supplied is perfect for my needs, so thanks again, happy new year and best wishes to you.

RS

Be a part of the DaniWeb community

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