[ Team LiB ] |
Recipe 11.11 Getting Checkbox Values11.11.1 ProblemYou want to determine the values (true or false) of checkboxes. 11.11.2 SolutionUse the getValue( ) method for each checkbox, or create a custom getValues( ) method for the checkbox group. 11.11.3 DiscussionThe getValue( ) method returns true if a checkbox is checked and false if the checkbox is unchecked: trace(myCheckBox0_ch.getValue( )); If you have created a checkbox group (see Recipe 11.10), you can add a custom method, getValues( ), that returns an array of the values for each checkbox in the group. The elements of the returned array contain three properties:
Here is our custom getValues( ) method, which you should add to your Form.as file for easy inclusion in future projects: // Create the new method, getValues( ), for the FCheckBoxGroupClass. FCheckBoxGroupClass.prototype.getValues = function ( ) { // The dataAr array is populated with the objects for each checkbox in the group. var dataAr = new Array( ); // Create two local variables for use in the for statement. var cb, obj; // Loop through every checkbox in the group. for (var i = 0; i < this.radioInstances.length; i++) { // cb refers to the current checkbox. cb = this.radioInstances[i]; // For each checkbox, create an object with name, label, and value properties. obj = new Object( ); obj.name = cb._name; obj.label = cb.getLabel( ); obj.value = cb.getValue( ); // Add the object to the array. dataAr.push(obj); } // Return the array of values. return dataAr; }; 11.11.4 See Also |
[ Team LiB ] |