Hello,
I have a select list and I am trying to add options to it, when I try to use add(option), I get the error Invalid Argument.
Here is the summary of the things I am doing,
I am getting the list from the server and then looping through the list and creating an option for each item and then adding option to array.
item = list.split(delimiter);
addOption = new Option(item[1], item[0]);
ArrayList[count] = addOption;
after building the array I am trying to load this array to the select list using this method.
LoadSelect(ArrayList,ddl);
LoadSelect(options,ddl)
{
ddl.options.length=0;
for (var i= 0; i < options.length; i++)
{
if(options[i] != null)
{
var Item = options[i];
ddl.add(Item);
}
}
}
I have a check box which will load the select list again, or if i move to a different tab in my page i have to load the list again. For loading the list for the second time i am calling the same method by passing the same array of options (ArrayList is global), but I get the error second time. I also tried reducing my list length, it works sometimes but suddenly i get the error.
I tried using the below method for creating the options, but it did not work
var optn = document.createElement(“OPTION”);
optn.text = item[1];
optn.value = item[0];
I also tried using this
ddl.options[numItems] = v_Item;
numItems++;
instead of ddl.add(), but I get “object does not support this property or method” error instead of invalid argument
Can someone please help me.