Start Building Professional
Web Apps Today


 
Categories Question details Back To List
Question  posted by C. Bernstein on Jun 15, 2009 06:02
open dhtmlx forum
Set a Selected Value Upon Initializing a Combobox

How would I go about setting a default value to be selected when a combo box is initialized and initially loaded onto the screen? I am trying to use getIndexByValue(), getOptionByLabel() but these are not working ( I assume these are not working because the combo box is not completely intialized yet). How do I work around this?


combo.loadXML("initFile.xml");
combo.getIndexByValue(val); //this returns -1
combo.getOptionByIndex(1); //this returns undefined
combo.getOptionByLabel(val); //this returns null
Answer posted by Alex (support) on Jun 15, 2009 08:03

Hello,

loadXML uses Ajax to load data - asynchronous loading. So, please use the following approach to call the mentioned methods after xml loading:

combo.loadXML("initFile.xml",doAfterXMLLoading);

function doAfterXMLLoading(){

var ind = combo.getIndexByValue(val); //this returns -1 
var option = combo.getOptionByIndex(1); //this returns undefined 
option = combo.getOptionByLabel(val); //this returns null
}