View Full Version : Output of comboBox?
SpiderArts
01-05-2007, 09:28 PM
Lets say i have a combo box.
I have some code that is based on the selection of the combo box.
The combo box has:
Human
Flakam
Drake
the comboBox instance name is "race" Selections and my code says something like
if (comboBox == "Drake"){
size.text = "Small";
speed.text = "20";
} else if (comboBox == "Flakam"){
size.text = "Medium";
speed.text = "30";
} else if (comboBox == "Human"){
How do i retrieve the value of the comboBox selection?
SpiderArts
01-06-2007, 12:08 AM
Lets say i have a combo box.
I have some code that is based on the selection of the combo box.
The combo box has:
Human
Flakam
Drake
the comboBox instance name is "race" Selections and my code says something like
if (comboBox == "Drake"){
size.text = "Small";
speed.text = "20";
} else if (comboBox == "Flakam"){
size.text = "Medium";
speed.text = "30";
} else if (comboBox == "Human"){
How do i retrieve the value of the comboBox selection?
Mazoonist
01-06-2007, 01:52 AM
myComboBox.addItem("Drake");
myComboBox.addItem("Flakam");
myComboBox.addItem("Human");
//
var oListener:Object = new Object();
oListener.change = function(oEvent:Object) {
if (oEvent.target.selectedItem.label == "Drake") {
size.text = "Small";
speed.text = "20";
} else if (oEvent.target.selectedItem.label == "Flakam") {
size.text = "Medium";
speed.text = "30";
} else if (oEvent.target.selectedItem.label == "Human") {
size.text = "Large";
speed.text = "40";
}
};
myComboBox.addEventListener("change", oListener);
In the above, "oEvent.target" identifies the object broadcasting the event. In this case, since you're only dealing with one object, it's the comboBox. So, in this case, "oEvent.target" is the same as saying "myComboBox." So you could also use "myComboBox.selectedItem.label" -- Anyway, selectedItem.label is the property with the value you wanted to retrieve. Hope that helps.
SpiderArts
01-06-2007, 04:12 AM
I figured it out, thank you...all i needed was
.value
that was an awefull lot of uneeded code, but thanx
Mazoonist
01-06-2007, 04:28 AM
It's not unneeded code, as you'll find out if you ever use comboBox to store a data value as well as a label. In that case, using value will return the data value instead of the label, which won't be what you want.
See, for each item in the combo box, you can also store a data value that the user doesn't see. Why would you want to do that? Well, one example might be a combo box that's a menu of links on your website. The data value might be the URL that the combo box selection takes you to. And really, the data property is there to contain whatever you want to store there. The label is what the user sees, and the data value is what's there but not shown.
Anyway, I guess for your purposes right now, using value is OK, but keep in mind that later if you ever want to use the data property too, it'll backfire on you. The correct property is selectedItem.label.
SpiderArts
01-06-2007, 06:02 PM
i just made the data and the lable the same.
vBulletin® v3.7.1, Copyright ©2000-2009, Jelsoft Enterprises Ltd.