Home > AJAX, ASP.Net, Javascript > Calculate Age from Selected Date in AJAX Calender Extender Using Javascript

Calculate Age from Selected Date in AJAX Calender Extender Using Javascript


Dear all,

try this example to Calculate age from Selected Date in AJAX Calender Extender Using Javascript


<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<asp:ScriptManager ID="ScriptManager1" runat="server" />
<asp:TextBox ID="txtDate" runat="server" />
<asp:ImageButton runat="server" ID="imgPopup" ImageUrl="~/Images/Calendar.png" />
<cc1:CalendarExtender ID="CalendarExtender1" OnClientDateSelectionChanged="DateSelectionChanged"
runat="server" TargetControlID="txtDate" PopupButtonID="imgPopup" />
<script type="text/javascript">
function DateSelectionChanged(e) {
var today = new Date();
var dob = e.get_selectedDate();
var months = (today.getMonth() - dob.getMonth() + (12 * (today.getFullYear() - dob.getFullYear())));
alert("Your age: " + Math.round(months / 12));
}
</script>
</form>
</body>
</html>

Hope this helps

Good Luck.

Advertisements
Categories: AJAX, ASP.Net, Javascript
  1. May 21, 2014 at 7:21 am

    Reblogged this on modyrefay.

  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: