This is a migrated thread and some comments may be shown as answers.

rad date picker age calcualte using javascript

8 Answers 280 Views
Input
This is a migrated thread and some comments may be shown as answers.
chandrasekaran
Top achievements
Rank 1
chandrasekaran asked on 28 Jan 2009, 09:41 AM
Hi,
 i have to calculate age when selecting a date in the rad date picker in client side using javascript. This should happen as soon as i select the date from the date picker. how can i do this. im new to teleric controls. Can anyone help me in this?

Regards,
chandruK

8 Answers, 1 is accepted

Sort by
0
Daniel
Telerik team
answered on 28 Jan 2009, 10:43 AM
Hello Chandrasekaran,

A possible approach is shown below:
<script language="javascript" type="text/javascript"
    function CalculateAge(sender, args) 
    { 
        var current = new Date(); 
        var day = 1000 * 60 * 60 * 24 
 
        var age = current - args.get_newDate(); 
        alert("You are " + Math.round(age / day / 365.25) + " years old"); 
    } 
</script> 
 
<div> 
    <telerik:RadDatePicker ID="RadDatePicker1" runat="server"
        <ClientEvents OnDateSelected="CalculateAge" /> 
    </telerik:RadDatePicker> 
</div> 

Let us know if you need more information.

Greetings,
Daniel
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
chandrasekaran
Top achievements
Rank 1
answered on 28 Jan 2009, 12:52 PM
Hi,
    Thank u very much for this valuable help
thx
chandrasekarank
0
chandrasekaran
Top achievements
Rank 1
answered on 28 Jan 2009, 01:04 PM
Hi,
  In firefox this event is not triggering.
thx
chandrasekaranK
0
Daniel
Telerik team
answered on 28 Jan 2009, 02:24 PM
Hello Chandrasekaran,

I tested the event on our online demos but I failed to reproduce the depicted problem. I'm using Firefox 3.05.
RadDatePicker Client-side Events

Best regards,
Daniel
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
chandrasekaran
Top achievements
Rank 1
answered on 28 Jan 2009, 02:44 PM

Hi,
 i am also using firefox3.05 only..this is my function 

function AgeCalculate(sender, args)

{

      var current = new Date();

       var txtDOB = document.getElementById('<%=txtDOB.ClientID %>');

      var byear = txtDOB.value.substring(0, 4)

      var CurrentDate = new Date();

      var age = parseInt(CurrentDate.getFullYear()) - parseInt(byear)

     

       var lblAgeCalculation = document.getElementById('<%=lblAgeCalculation.ClientID %>');

      lblAgeCalculation.innerText = "Age " + age + " year(s)";

}

 

 

<radCln:RadDatePicker ID="txtDOB" runat="server" MinDate="01/01/1900">

  <ClientEvents OnDateSelected="AgeCalculate"/>

 

<Calendar ID="Calendar1" runat="server" ShowOtherMonthsDays="false" ShowRowHeaders="false"  Skin="WebBlue" BorderWidth="1">

</Calendar>

<DateInput MaxLength="10" ReadOnly="false" MinDate="01/01/1900" >

</DateInput>

 <DatePopupButton HoverImageUrl="~/Images/datePickerPopupHover.gif" ImageUrl="~/Images/datePickerPopup.gif"

TabIndex="6"></DatePopupButton>

</radCln:RadDatePicker>

 

 

 

 

 

 

 

 

 

 

thx
chandrasekarank

 

 

 

0
chandrasekaran
Top achievements
Rank 1
answered on 29 Jan 2009, 04:32 AM
 

Hi,
 i am also using firefox3.05 only..but its not firing the event ...this is my function 

function AgeCalculate(sender, args)

{

      var current = new Date();

       var txtDOB = document.getElementById('<%=txtDOB.ClientID %>');

      var byear = txtDOB.value.substring(0, 4)

      var CurrentDate = new Date();

      var age = parseInt(CurrentDate.getFullYear()) - parseInt(byear)

     

       var lblAgeCalculation = document.getElementById('<%=lblAgeCalculation.ClientID %>');

      lblAgeCalculation.innerText = "Age " + age + " year(s)";

}

 

 

<radCln:RadDatePicker ID="txtDOB" runat="server" MinDate="01/01/1900">

  <ClientEvents OnDateSelected="AgeCalculate"/>

 

<Calendar ID="Calendar1" runat="server" ShowOtherMonthsDays="false" ShowRowHeaders="false"  Skin="WebBlue" BorderWidth="1">

</Calendar>

<DateInput MaxLength="10" ReadOnly="false" MinDate="01/01/1900" >

</DateInput>

 <DatePopupButton HoverImageUrl="~/Images/datePickerPopupHover.gif" ImageUrl="~/Images/datePickerPopup.gif"

TabIndex="6"></DatePopupButton>

</radCln:RadDatePicker>

 

 

 

 

 

 

 

 

 

 

 

 

thx
chandrasekarank

 

 

 

 

 

 

0
Daniel
Telerik team
answered on 02 Feb 2009, 12:42 PM
Hello Chandrasekaran,

I attached a modified example (based on your code) to this post. Please test it locally and let me know whether this helps.

Regards,
Daniel
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
chandrasekaran
Top achievements
Rank 1
answered on 10 Feb 2009, 05:16 AM
Hi,
    Thank u very much ..the sample r very usefull and i have implemented it to project..it is a dedicated help tome ..once again thank you..
chandrasekarank
Tags
Input
Asked by
chandrasekaran
Top achievements
Rank 1
Answers by
Daniel
Telerik team
chandrasekaran
Top achievements
Rank 1
Share this question
or