You are viewing limited content. For full access, please sign in.

Question

Question

Calculated Age Field

asked on January 9, 2018

I'm using LF Forms 10.2. Based on the date entered in the DOB field (variable: DOB), I would like the Age field (variable: Age) automatically calculated and populated while remaining Read Only. Has anyone had any luck in this area?

 

0 0

Answer

SELECTED ANSWER
replied on January 10, 2018

In the Age field you can use this formula

=DATEDIF(DOB,TODAY(),"Y")

The Age field can be set to Read only using the fields Read Only checkbox

1 0
replied on January 10, 2018

Preciate your help Steve Knowlton.

0 0

Replies

replied on January 9, 2018

Assuming that the DOB field uses the css class, dob, and the Age field uses the css class, age, you can use the following Javascript

  $('.dob input').on('change', function() {
    var today = new Date();
    var birthDate = new Date($('.dob input').val());
    var age = today.getFullYear() - birthDate.getFullYear();
    var m = today.getMonth() - birthDate.getMonth();
    if (m < 0 || (m === 0 && today.getDate() < birthDate.getDate())) {
        age--;
    }
    $('.age input').val(age);
  });
1 0
replied on January 10, 2018

Preciate your help Alexander Huang.

0 0
You are not allowed to follow up in this post.

Sign in to reply to this post.