Calculate age based on date input?

emills01 05 Jun, 2015
I have a field that asks for the visitor's birth date as plain text (NOT a date selection box because we didn't like the formatting on that - there is a prompt to format as mm/dd/yyyy).

Even if I have to change the type of input used to enter the date, is it possible to have a field that is automatically completed with the person's age depending on what they enter in the birth date field?
GreyHead 06 Jun, 2015
Hi emills01,

First, you can specify the date format in the ChronoForms date-picker - there are d-m-Y, m-d-Y and Y-m-d options.

You can add JavaScript to read a date entry and convert to an age (iirc there was a thread here a few weeks ago about doing this calculation).

The problem you will have is on interpreting a free-format date entry with any degree of reliability. You can get many different interpretations and some are ambiguous.

Bob
emills01 08 Jun, 2015

The problem you will have is on interpreting a free-format date entry with any degree of reliability. You can get many different interpretations and some are ambiguous.



Could you explain a little bit more what that means and what problems I might run into?
GreyHead 08 Jun, 2015
Hi emills01,

If you let users enter a free-form date - even with some guidance - you will get all kinds of different entries. 4 May '69, August 13th 1908, 4-4-22 . . . You have to be able to read and interpret all of those.

Bob
emills01 09 Jun, 2015

You can add JavaScript to read a date entry and convert to an age (iirc there was a thread here a few weeks ago about doing this calculation).



Could you direct em to this or let me know what it is called? I looked but I'm not seeing a recent thread about it.
emills01 11 Jun, 2015
Thanks so much. Adding code like that is a little bit of a new territory for me.

Where does the code go?

Also, does Chronoform have any other options for date pickers? We had some issues with visitors not being able to navigate the original one we had, which is why we went to the plain text input.
emills01 11 Jun, 2015
...OR is it possible to use a mask with a plain text input for the date and force the code to use that?
GreyHead 15 Jun, 2015
Hi emills01,

You have two different questions here.

+ to calculate the age you need some code either JavaScript in the form display or PHP after it submits.

+ + to input a date you can use a masked input there's a masking option and a FAQ about it; or you can use any jQuery datepicker, there's a FAQ about using the jQuery UI one, The default ChronoForms one is OK but for a date of birth you should set it to show the year selector.

Bob
This topic is locked and no more replies can be posted.