Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
I would like to know if there is a simple way to find the age of a person based on DOB entered and then display it on the form.
Example:
DOB: 12/27/1997 Age is: 18
Comments
Comment #2
Vako CreditAttribution: Vako commentedComment #3
Subhransu.addweb CreditAttribution: Subhransu.addweb at AddWeb Solution Pvt. Ltd. commentedFor that you need to alter webform using
hook_form_alter(&$form, &$form_state, $form_id)
and apply below code for your fields( i.e. dob,age).Feel free to contact me incase of any query/concern regarding this.
Thanks!
Comment #4
Vako CreditAttribution: Vako commentedThank you Denisha for the reply. Can you please elaborate a little more as where I can put such a code and how I can have it displayed beside the DOB field.
Comment #5
Subhransu.addweb CreditAttribution: Subhransu.addweb at AddWeb Solution Pvt. Ltd. commentedFor you purpose you require to place that calculation in js code. You can add the below code in your js file. Take two fields (dob, age).
Feel free to contact me in case of any query/concern regarding the same.
Thanks!
Comment #6
ashhishhh CreditAttribution: ashhishhh at Valuebound commentedComment #7
Vako CreditAttribution: Vako commentedThank you Denisha. The js file that you mentioned, is it the \sites\all\modules\webform\js\webform.js file?
and how can I control the location of the Age display?
I will try it and let you know how it works.
Comment #8
Subhransu.addweb CreditAttribution: Subhransu.addweb at AddWeb Solution Pvt. Ltd. commentedNop Vako! Not there, please place it in your theme js file (i.e./sites/all/themes/yourtheme/js/custom.js).
.webform-component--dob:- Please place your dob here.
Hope this helps you.
Comment #9
Vako CreditAttribution: Vako commentedI did insert the above code in the theme's custom.js file, replaced
.webform-component--dob
with.webform-component--applicant_dob
But where will the Age value be visible, or how can I control the location of the Age value?
In your code there are
#edit-submitted-bod-###
values, shouldn't it be#edit-submitted-dob
instead?I believe we need to replace those with the webform equivalent as well?
Comment #10
Liam MorlandOver a year old; re-open if you still need help.