/    Sign up×
Community /Pin to ProfileBookmark

htmlfile Invalid Argument error

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.

to post a comment
JavaScript

3 Comments(s)

Copy linkTweet thisAlerts:
@KorOct 13.2009 — Hello,

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];

[/QUOTE]

This should work. But you should also [I]append[/I] the new created OPTION element to the SELECT parent on using [B]appendChild()[/B] method. Can we see this version of your code?
Copy linkTweet thisAlerts:
@anni07authorOct 13.2009 — Thanks Kor for replying to my post.

Regarding this method

var optn = document.createElement("OPTION");

optn.text = item[1];

optn.value = item[0];

I am trying to create an array of options first and then loading the array to the select list.

ArrayList[Count] = optn; this is how i am adding option to the array and later I am calling the below method

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);

}

}

}





Regarding your solution

"But you should also append the new created OPTION element to the SELECT parent on using appendChild() method"

Where should I append the option now, as I am adding the options to the array. Please let me know what I should do for this method.



Thanks,

Asma.
Copy linkTweet thisAlerts:
@anni07authorOct 13.2009 — One more point I would like to add to my problem is, my two methods(new option(); createElement("OPTION")? are working fine when i load the list for the first time, and when i click the checkbox or click on tab, i am calling this loadselect() method passing the same array again, then it gives me the error.

I am not changing the value of array it is same, but when I looked carefully the outerHTML value of the Array when I call the loadselect method for the first time looks like <option value="userid"></option> (which is missing the text in between option and closing of option) where as when i load the array for the second time I get error which has outerHTML value of <option value="userid">username</option> and it gives me error which is infact correct.

I thought since the list is lengthy may be some delay is causing the array to losing the value. I tried to shorten the list , it works for me for even when i click the check box and when I click on the tab, it loads the select list perfectly. But after sometime it will start giving me the error.
×

Success!

Help @anni07 spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.18,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...