...

View Full Version : How to add events to HTML Listbox at runtime



Me_Himanshu
10-10-2007, 06:14 AM
Hi all....
I am using firefox...
I want to add a particular event to listbox ...
my listbox name is 'ListAudioIn' and i am trying

oOption = document.createElement("OPTION")
oOption.text = "real player"
oOtion.value = 0;
ListAudioIn.add(oOption);

And i am getting an error: ListAudioIn.add is not a function

While other function calls like ListAudioIn.length & ListAudioIn.Remove are properly working......

THEN I TRIED....


ListAudioIn.options[INDEX] = new Option("Text", "Value");

I gave an integer value to 'INDEX'

Now I am getting an error..

The function ListAudioIn.options has no properties...

Help!!!!!

felgall
10-10-2007, 08:23 AM
Try:


ListAudioIn.options[ListAudioIn.options.length] = new Option('Real Player','0');

That should add to the end of an existing array of options. If you want to replace the existing options then set ListAudioIn.options.length to zero first.

Note that you need 'document' and the form name added on the front of ListAudioIn whereever it occurs for the code to work. So if your form is named 'audioForm' then it would be document.audioForm.ListAudioIn.options



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum