Using Components > Writing change handler functions for components > Single-selection forms |  |

Single-selection forms

In the following example, `onChange` is a handler function specified for two CheckBox components. The handler function accepts an instance of a changed component as a parameter, uses a series of `if/else` `if` statements to determine which check box instance is selected and enables either `listBox1` or `listBox2` depending on the value of the check box instance.

    function onChange(component)
    {

    if (component._name=="check1") {
    	listBox1_mc.setEnabled(component.getValue());
    } else if (component._name=="check2") {
    	listBox2_mc.setEnabled(component.getValue());
    }
    }

Another way of accomplishing the same thing is to specify a different `changeHandler` function for each CheckBox component, as shown in the following example:

For the `check1` instance, specify `onCheck1` as the Change Handler parameter on the Parameters tab in the Property inspector. You must define the `onCheck1` function in the same Timeline as the `check1` component instance. If the user selects the `check1` instance of the check box, the list box instance `listBox1` is enabled.

    function onCheck1(component)
    {

    	listBox1_mc.setEnabled(component.getValue());
    }

For the check box instance `check2`, specify `onCheck2` for the Change Handler parameter on the Parameters tab in the Property inspector, and define the `onCheck2` function in the same Timeline as the `check2` component. If the user selects the `check2` instance of the check box, the list box instance `listBox2` is enabled.

    function onCheck2(component)
    {

    	listBox2_mc.setEnabled(component.getValue());
    }