Dynamically adding to a Select box


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 2 of 2

Thread: Dynamically adding to a Select box

  1. #1
    Aaron Chorpenning Guest

    Dynamically adding to a Select box


    I use this code to dynamically add <options> to a select box. In IE it works
    fine, but I don't think it is supported in NS6. Anyone know of a way to do
    this in Netscape 6.1?

    var eNewItem = document.createElement("<OPTION value='" +sValue +"'>");
    eNewItem.text = sText;
    document.getElementById("text").add(eNewItem);

    Any help here would be great!

  2. #2
    aj Guest

    Re: Dynamically adding to a Select box


    "Aaron Chorpenning" <terak@lords.com> wrote:
    >
    >I use this code to dynamically add <options> to a select box. In IE it works
    >fine, but I don't think it is supported in NS6. Anyone know of a way to

    do
    >this in Netscape 6.1?
    >
    >var eNewItem = document.createElement("<OPTION value='" +sValue +"'>");
    >eNewItem.text = sText;
    >document.getElementById("text").add(eNewItem);
    >
    >Any help here would be great!


    yes I just recently had to dynamically add some countries to an option list.
    check out the option object. I'd make the hieght > 1 of the options once
    you add more options, otherwise you get this ugly little scroll box
    my code had an array of objects, in which i assigned the property of that
    'ith' object in the loop to a new option object and thus adding it to the
    end of the current option list i had.

    for (i=0; i<arrObj.length; i++)
    {var newOpt = document.forms.f1.CountrySelection.options;
    newOpt[i] = new Option(arrObj[i].countryName);
    newOpt.text=arrObj[i].countryName;
    newOpt.value=arrObj[i].countryName;
    }


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center