Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New to the CF scene
    Join Date
    Oct 2007
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    How to add events to HTML Listbox at runtime

    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!!!!!

  • #2
    Master Coder felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, Australia
    Posts
    6,609
    Thanks
    0
    Thanked 645 Times in 635 Posts
    Try:

    Code:
    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
    Stephen
    Learn Modern JavaScript - http://javascriptexample.net/
    Helping others to solve their computer problem at http://www.felgall.com/

    Don't forget to start your JavaScript code with "use strict"; which makes it easier to find errors in your code.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •