CheckBox: controls dependent on a checkbox option

Summary

When you have a control that is dependent on whether a checkbox is selected or not.

Body

When you have a control that is dependent on whether a checkbox is selected or not.  In this example the dependent controls are description textboxes.

*Note: Checkboxes are treated as arrays

_______________________________________________________________________

if (Trigger.value === 'Yes') {
	Checkbox_Name.enabled = true;
	Checkbox_Name.required = true;

	//declaring variables of the options 
	var Variable_Name1 = false;
	var Variable_Name2 = false; 
	var Variable_Name3 = false;
	
	//For loop for the checkbox options
	for (var i = 0; i < Checkbox_Name.value.length; i++) {
    
		if (Checkbox_Name[i].value === 'Option_Name1') {
			Variable_Name1 = true;
		}

		if (Checkbox_Name[i].value === 'Option_Name2') {
			Variable_Name2 = true;
		}

		if (Checkbox_Name[i].value === 'Option_Name3') {
			Variable_Name3 = true;
		}
	}
    //if this scenario happens then the Describe_Box# is enabled and required
	if (Variable_Name1 === true) {
		Describe_Box1.enabled = true;
		Describe_Box1.required = true;
	} else {
		Describe_Box1.enabled = false;
		Describe_Box1.value = null;
		Describe_Box1.required = false;
	}

	if (Variable_Name2 === true) {
		Describe_Box2.enabled = true;
		Describe_Box2.required = true;
	} else {
		Describe_Box2.enabled = false;
		Describe_Box2.value = null;
		Describe_Box2.required = false;
	}

	if (Variable_Name3 === true) {
		Describe_Box3.enabled = true;
		Describe_Box3.required = true;
	} else {
		Describe_Box3.enabled = false;
		Describe_Box3.value = null;
		Describe_Box3.required = false;
	} 

/*if Yes is not selected then Checkbox_Name is not enabled, required, and the value is null,
values in the Describe box also becomes null **/
} else {

	Checkbox_Name.enabled = false;
	Checkbox_Name.required =false;
	Checkbox_Name.value = null;

	Describe_Box1.value = null;
	Describe_Box2.value = null;
	Describe_Box3.value = null; 
}

 

Details

Details

Article ID: 51433
Created
Tue 4/3/18 3:53 PM
Modified
Thu 4/12/18 11:35 AM