View Full Version : Select Text In Combobox

02-18-2003, 01:50 AM
What is the command to set the selected text in a non-editable combobox?mycombobox.setSelectedText("whateverIwantSelected")Something like this?

02-18-2003, 03:12 AM
I managed to change the text in the labels array ok but I cant seem to get it to alter the onscreen display:
_level0.mycombobox.labels[0] = "new text";

Anybody else?

02-18-2003, 04:25 AM
This works, but it's a slow way to get it done. Any other takers?
while(mcForm.cmbYear.getValue() != items[1]){
i = i + 1

02-18-2003, 06:34 AM
Um... Call me dumb, brother... But I don't get your question... What do you mean by 'set the selected text in a non-editable combobox'??? What are you trying to do??? :(

02-18-2003, 02:25 PM
No problem...let's say I have a combobox with 50 different years in it which are not in order. After I dynamically load the fifty different years in it I want the combobox to automatically select the year "1997", and stay there until the user changes it. I can't get it to do this because I don't know the index number of the year "1997" in the combobox. Make sense?

02-18-2003, 09:32 PM
Well... If that is the case, you have to run the loop to see if '1975' exists or not as you have in the while loop... It might take some time to see if that data exists or not, but I don't think it will be that bad since you are not supposed to add more than 400 data in the combobox anyways... Doing a loop with 400 elements will take no more than a second, I think... :DdataArray = new Array(1955, 1935, 1958, 1983, 1975, 1936, 1988, 1973, 1989, 1992, 1945, 1958, 1963, 1934, 1977);
_level0.attachMovie("FComboBoxSymbol", "testCB", 100, {_x:25, _y:25});

for (i = 0 ; i < dataArray.length ; i++)
if (_level0.testCB.getItemAt(i).label == "1975")
}I just added 'break;' to get out of the loop as soon as the data has been found, or the default will set it to the first item in the array...

02-18-2003, 10:02 PM
That's similar to what I was trying in a previous post, but I have decided to make the comboboxes editable. I will just have to write a check to make sure that the entry is valid. Thanks! Hope all is well.

02-18-2003, 10:22 PM
Arg... I can't find this darn thing... I have seen freddycodes' example within a week period, but I can't seemd to find that thread... Anyways... freddycodes posted this... Check it out and see if you want this... If you do, all you have to is to ask freddycodes... :D

02-19-2003, 10:55 PM
I don't understand? I went to the link, but there was no selected text in the combobox....

02-20-2003, 12:12 AM
Oh... There is not preselected text in that combobox... I just showed you the url because I wanted you to see how other features are done in there... There are some nice features in his combobox... :)

02-20-2003, 03:09 AM
Oh, my bad. I was looking for the selected text thing. I'll take a look at it again. Thanks yet again!

02-20-2003, 04:39 AM
Well if you knew the initial value you wanted set, you could just add that one first. Consider this

years = [];
for(var i=1990;i<2010;i++) {
if(i != 1998) years.push({data:i,label:i});

02-20-2003, 02:08 PM
I'm not familiar with "push", but if you're saying that when I populate the combobox, just stick the one I want selected in first, that would work. Except I don't find out what they select till after combobox is already filled. I can't believe that the combobox component doesn't have a function that selects certain text in the combobox....guess I'm just used to VB.