Click here to Skip to main content
15,908,626 members
Please Sign up or sign in to vote.
3.00/5 (1 vote)
I want to calculate the age from the date. when i click the calendar image i will get the date in DOB field at the same time i want to calculate the age also. How to do this from the Javascript.

[moved from answer]
My Question is , i don't know how to pass the age control id in the Showcalendar javascript function [ any calendar function ]. all calendar functions are just creating the calendar and giving the selected date.
Posted
Updated 11-Oct-10 0:38am
v2
Comments
Ankur\m/ 11-Oct-10 6:41am    
Please do not add answer if you need to clarify something with the answerer. He is not notified. Instead use 'Add Comment' below his answer, like I did.

I guess you need something like this - http://www.hscripts.com/scripts/JavaScript/age-calculator.php[^].
 
Share this answer
 
Well, I don't see why you would not be able to do it, if you just try it.

You got a date from a Calendar. Based on selection, you just need to find the difference of date selected and today's date. Now, just display the difference as years, months and days.
 
Share this answer
 
You can call the function to calculate age on "onchange" event of the text box in which you are getting the date selected from the calendar.




function calculateAge(txtBox)
{
/// calculate age by using the value of txtBox
}
 
Share this answer
 
Comments
Ankur\m/ 11-Oct-10 6:39am    
[moved from answer]
Robymon wrote:
onChange event is not working . i tried with some other events. no luck.
saini arun 11-Oct-10 7:53am    
Please post the HTML code generated for text field which uses calendar control to get the date.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900