How to test if a checkbox is selected in Adobe Livecycle Designer dynamic form


Here is a simple way to get the status of a Check Box (to know if a Check Box is ticket or not) in a dynamic form created with Adobe Livecycle Designer.

/**
 * @param {Object} elemetToCheck The element you want to check
 * @return {Boolean} true if is ticked; false if it's not ticked
 */
function isTicked(elemetToCheck) {
    return (elemetToCheck.rawValue == elemetToCheck.items.nodes.item(0).value) ? return true : return false;
}

The first element in the condition (elemetToCheck.rawValue) gets the current value of the Check Box, which can be either the value you wrote in On value or Off value.

2014-08-28_123901

The second element in the condition (elemetToCheck.items.nodes.item(0).value) gets the value which you wrote in the On Value (in this example is “THEM-OTH”).

Usage (example)

If you have a list of Check Boxes and the last one is “Other” and you need to show a Text Field for the user to write his data, here is how you can do it:

In the ::change event of the checkbox “Other” you put the following script:

if(isTicked(this)) {
    //explainTextField is the name of the Text Field you want to show or hide
    explainTextField.presence = "visible";
} else {
    explainTextField.presence = "hidden";
}

Please check here my article on different ways of hidding and showing parts of a dynamic form.

Advertisements