Recipe 13.14. Retrieving Values from Checkboxes and Toggle
|
Recipe 13.15. Retrieving Values from Radio Button GroupsProblem
You want to retrieve a value from a
SolutionUse the radio button group's selectedData property. DiscussionAs discussed in Recipe 13.5, radio buttons are typically used in groups. Therefore, you usually will want to retrieve the value from the selected radio button in the group. In order to do that, all you need to do is use the selectedData property of the radio button group.
Recall that when you create a radio button instance, you set the
groupName
parameter. The
groupName
parameter defines how the radio buttons are associated. Not only that, but it also creates a new ActionScript object with that same name. For example, if you create five radio buttons and assign each of them the group
If you have defined a data parameter value for the radio buttons, the radio button group's selectedData property will return the data value for the selected radio button. However, if you have not defined the data parameter value for the radio buttons, the selectedData property will simply return the chosen radio button's label value.
In most scenarios, you will want to retrieve the selected radio button value only after the
var oListener:Object = new Object();
oListener.click = function(oEvent:Object):Void {
trace(rbgQuizQuestion.selectedData);
};
cbtSubmit.addEventListener("click", oListener);
See AlsoRecipe 13.5 |
Recipe 13.16. Retrieving Date ValuesProblemYou want to retrieve a date from a date form control. SolutionIf you are using a date chooser or date field, use the instance's selectedDate property. Otherwise, use the FormController component to handle your form processing. Discussion
The date chooser and date field
var oListener:Object = new Object();
oListener.click = function(oEvent:Object):Void {
trace(cdcCalendar.selectedDate);
};
cbtSubmit.addEventListener("click", oListener);
If you are not using a date field or a date chooser, but rather a text input or input text field, you can simply retrieve the information the user has input via the text property as discussed in Recipe 13.11. However, as was mentioned in Recipe 13.9, verifying that the information represents a valid date requires some advanced ActionScript code. Therefore, unless you are very familiar with ActionScript, you will likely find it much simpler to use a FormController component to manage your form. See alsoRecipe 13.9, Recipe 13.17 |