Using JavaScript to check form elements and create relationships between them

JavaScript gives you a way to validate input for several form elements at the same time and create relationships between them. Since you can use all of the operations and functions offered by JavaScript, you can make things as simple or complex as necessary.

Access to the form fields – and therefore to the input that users make into the form – is handled in JavaScript using the technical name of the respective form field.

Adding JavaScript

  1. The Validation with JavaScript section is part of the page properties. This is where you add your JavaScript.

Integrated JavaScript functions

Formcentric provides you with the following additional JavaScript functions for handling date values and drop-down lists:

  1. parseDate
  2. parseAge
  3. isEmptyList
  4. isSelected

parseDate

The JavaScript parseAge function converts the value of an input field into a JavaScript object of the Date type.

For this to work, you need an input field that is validated with the Date validator and expects a date as input from users.

As the first parameter, enter the date format in JavaScript that you have specified for the input field with the Date validator (e.g. dd/MM/yyyy). As the second parameter, enter the technical name that you have given the input field (e.g. training).

parseAge

The JavaScript parseAge function calculates a person’s age based on their date of birth.

For this to work, you need an input field that is validated with the Date validator and expects the birthdate as input from users.

As the first parameter, enter the date format in JavaScript that you have specified for the input field with the Date validator (e.g. dd/MM/yyyy). As the second parameter, enter the technical name that you have given the input field (e.g. birthday).

isEmptyList

The JavaScript isEmptyList function checks whether a selection was made from a form field in which users can make a selection, i.e. from a drop-down list or a single or multiple choice field.

To use the function, enter the technical name of the corresponding form field as the parameter (e.g. newsletter).

isSelected

The JavaScript isSelected function checks whether users have selected a specific option from a specified drop-down list or single/multiple choice field.

In JavaScript, enter the technical name of the form field with the selection as the first parameter (e.g. newsletter). As the second parameter, enter the value of the option (e.g. yes) that you want to check.

Feedback