Getting Selected Value from Combo

Hello,

I have a combo loaded from a database table and I set the current value in it from a grid by using

combo.setComboValue(profile);

the value “profile” is one of the existing ones in the combo list.

When I try to recover the index of the selected value in the combo I get a null, since it appears that setComboValue is setting the text but not selecting the actual value with the same text in the combo.

I have bee unable to get the value & index unless the user actually selects manually a value from the combo.
So the question is, how can I get the index of the value in the combo that is the same I have written by setComboValue?

Thanks in advance.

Javier

Hello,

check that the value is set after xml loading:

combo.loadXML(url,function(){
combo.setComboValue(profile);
})

And this is how to get an option index by its value:

var index = combo.getIndexByValue(value);

Hello Alexandra:

Thanks for your reply, but I had already tried it to no avail.

The statement
combo.setComboValue(profile);
Fills the combo with the value of profile, but does not select any actual value in the combo.

After setting the value with it, I get a -1 when calling combo.getIndexByValue(value);

I have tried almost everything but I only can get the actual Index value if a value has been manually selected in the combo.

Here is the code I’m using:
Initializing the combo:

Setting the value:
mygrid.attachEvent(“onRowSelect”,function(Id){

profile = mygrid.cells(Id,3).getValue();
combo.setComboValue(profile);
});

Getting it to update the database:
combo.getIndexByValue(profile)); (returns -1)

or

combo.getSelectedValue(); (returns null)

Un saludo

Javier

profile is option value (key) or text?

If it is value, the following must work:

combo.setComboValue(profile);
var i = combo.getIndexByValue(profile);

If it is text, you need to use another approach:

var value = combo.getOptionByLabel(profile).value;
combo.setComboValue(value);

Thank you very much.
It works like a charm.

Un saludo.

Javier