2 Replies - 10994 Views - Last Post: 18 March 2005 - 11:17 PM

#1 Speechist  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 1
  • View blog
  • Posts: 97
  • Joined: 02-December 04

Graduation Date Calculator

Posted 18 March 2005 - 10:28 AM

I'm looking for a straight-forward, self-contained JS that takes a date (someone's birthdate in mm/dd/yyyy format) and calculates the YEAR when that person will turn 18. I'm integrating the script into a PDF form using fields so it's not web-based. Most of the scripts available are htm-form based and that's not what I need.

I've tried some basic JS that takes a variable's value and performs a simple addition action but I'm not getting what I'm after. It has to be a Javascript.

Thanks in advance! B)

Is This A Good Question/Topic? 0
  • +

Replies To: Graduation Date Calculator

#2 Amadeus  Icon User is offline

  • g+ + -o drink whiskey.cpp
  • member icon

Reputation: 248
  • View blog
  • Posts: 13,506
  • Joined: 12-July 02

Re: Graduation Date Calculator

Posted 18 March 2005 - 11:09 AM

<script language="javascript">
var reply = prompt("Please enter your date of birth (mm/dd/yyyy)", " ");
var newstring = new String(reply);
var arrTemp = new Array();
arrTemp = newstring.split("/");
var year = parseInt(arrTemp[arrTemp.length-1]);
year += 18;
alert("You were born in " + parseInt(arrTemp[arrTemp.length-1]) + "\nYou will graduate in the year of our Lord " + year);
</script>


As an FYI, you could also use the javascript Date object, but it didn't seem necessary. Please note that this does not validate user input...it is always wise to validate.
Was This Post Helpful? 0
  • +
  • -

#3 Speechist  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 1
  • View blog
  • Posts: 97
  • Joined: 02-December 04

Re: Graduation Date Calculator

Posted 18 March 2005 - 11:17 PM

Thanks Amadeus,

I'll give this a try when I get back to the office. B)
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1