TOPIC:

Age element to calculate from birthday element 2 years 9 months ago #217719

  • Topic Author
  • apexbit
  • Offline
  • Junior Breezer
  • Junior Breezer
  • Posts: 69
  • Thanks: 0
Hi guys,
Is there a possibility to have an "Age" element that could automatically calculate the age of a person from a previous "Birthday" element data input.
The "Birthday" element should be a Responsive Calendar element type.
Thank you

Please Log in or Create an account to join the conversation.

Age element to calculate from birthday element 2 years 9 months ago #217733

  • marko.bosnjak
  • Offline
  • User is blocked
  • User is blocked
  • Posts: 2222
  • Karma: 44
  • Thanks: 279
Hello,

yes, that is possible.
Please follow these few steps:

1) Create a Responsive Calendar named "birthday" and set the following format "dd/mm/yyyy".

2) Create a textfield named "age".

3) Go to form properties > Advanced tab > More options > Scripts > Initialization Script > Type > Custom and paste this code in the framework:
function ff_birthday_form_init()
{
setInterval('showage()',500);
}

function showage(){
        var one_year=1000*60*60*24*365;
        var date1 = new Date();
        
        var dob= ff_getElementByName('birthday').value;
        var tmp=ff_getElementByName('birthday').value.split("/");
        var date2=new Date(tmp[2],tmp[1]-1,tmp[0]);
       
        var pattern = /[0-3][0-9]\/(0|1)[0-9]\/(19|20)[0-9]{2}/; //Regex to validate date format (dd/mm/yyyy)
        if (pattern.test(dob)) {
            var y1 = date1.getTime(); //getting current year
            var y2 = date2.getTime(); //getting dob year
            var diff=Math.floor((y1-y2)/one_year);
            
            ff_getElementByName('age').value=diff;    
        }
}
NOTE: Replace "birthday_form" in the first line of the script with the correct name of your form.

That's it.
I'll attach you the form.
Install it and test it out.
Let me know if it's working.

Regards,
Marko
======================================
Support Crosstec and get ALL EXTENSIONS and professional support for just $5
Here!
======================================
Need to renew Pro Support?
Buy Here!
======================================
Satisfied?
Consider a Membership!
======================================
Follow us on Facebook!
Attachments:

Please Log in or Create an account to join the conversation.

Last edit: Post by marko.bosnjak.

Age element to calculate from birthday element 2 years 9 months ago #217949

  • Topic Author
  • apexbit
  • Offline
  • Junior Breezer
  • Junior Breezer
  • Posts: 69
  • Thanks: 0
Works great !!! Thank you !

Please Log in or Create an account to join the conversation.

Age element to calculate from birthday element 2 years 9 months ago #217988

  • marko.bosnjak
  • Offline
  • User is blocked
  • User is blocked
  • Posts: 2222
  • Karma: 44
  • Thanks: 279
Hello,

that's great. :woohoo:
Let us know should you need anything else.

Regards,
Marko
======================================
Support Crosstec and get ALL EXTENSIONS and professional support for just $5
Here!
======================================
Need to renew Pro Support?
Buy Here!
======================================
Satisfied?
Consider a Membership!
======================================
Follow us on Facebook!
The following user(s) said Thank You: apexbit

Please Log in or Create an account to join the conversation.

  • Page:
  • 1
Moderators: ForumSupport
Time to create page: 0.045 seconds

BreezingForms Pro 1.4.7 for WordPress Released!

Available in the membership section.

September Discount!

Massive discounts on all subscriptions!

Get Your Subscription Here

Quick Links

Downloads

BreezingForms

ContentBuilder

BreezingCommerce

Templates

Documentation

BreezingForms

ContentBuilder

BreezingCommerce

Apprendre BreezingForms (French Community)

Apprendre et maîtriser BreezingForms par des tutoriels et exemples, le tout en français

breezingforms.eddy-vh.com

Questions et réponses sur les forums de l'AFUJ

AFUJ

Special Offer

Summer Sale! All subscriptions at a special price!

Includes prio support, all of our current and future Joomla!® extensions and Joomla!® templates for the duration of your membership.

Get it from here

3rd Party Discount - 25% Off

We help you to keep your costs under control. If you are a new member and purchased a form building tool from a different form vendor, then you'll get a 25% discount on our subscription plans.

How to receive the discount:

Send us a quick email to sales@crosstec.org with a proof of purchase (for example a paypal receipt), await payment instructions and enjoy your membership!