JavaScript Tips & Tricks
Table of Contents
- What is javascript?
- What is the Date element?
- What are Dynamic Values?
- How do I calculate age using the Date element?
What is javascript?
Javascript is a dynamic computer programming language whose implementations allow client-side script to make dynamic content.
Click here for more in-depth tutorials and learn more about javascript.
What is the Date element?
The Date Element allows users to capture the past, present or future date stored in a localized format. In the U.S., the date will appear as Month-Day-Year.
Click here for more information on the Data element and how to utilize it on your forms.
What are Dynamic Values?
Dynamic Values are used to apply a value to an element based on specific conditions.
Click here for more information on Dynamic Values and how to implement them.
How do I calculate age using the Date element?
To calculate age using the Date element, please follow the instructions below.
PLEASE NOTE: In this example, the Date element is used to enter the birth date and the Text element will calculate the Age.
STEP 1 . From inside the form builder, click the Page Level JavaScript icon your form.
STEP 2. In the Page Level JavaScript field of the form properties, place the following:
function calcAge(dateString) {
var birthday = new Date(dateString);
return ((Date.now() - birthday) / (31557600000));
}
Then Save and Close.
STEP 3. Create a Date element with a data column name of birth_date.
STEP 4. In the Dynamic Value field of the element, put the following:
Date()
STEP 5. Add a Text element to your form with a data column name of my_age.
STEP 6. In the Dynamic Value field of the Text element, put the following:
calcAge(birth_date)
In the Text element, we are calling the function in the Page Level JavaScript and running the function on the Date element entered.
STEP 7. Save your form.
Comments
1 comment
Can the dynamic value field be just an expression instead of an assignment like that?
Please sign in to leave a comment.