Adding options to a drop-down list in one go with JavaScript

Posted on 2007-07-31
Last Modified: 2013-11-27
Is there a way  in JaveScript that you can add an array of options to a drop-down list in one go rather than iterating through the array and adding each option individually?
Question by:Silas2
    LVL 9

    Expert Comment

    without using any loop (for,foreach,...) you cannot do that
    LVL 14

    Accepted Solution

    Well as above not possible without looping.
    If interested in looping see this.

    Hope it helps

    Author Comment

    Thank you for that, but can you think of a way of overcoming the problem that I have: I have a grid/table where each row has a number of drop-downs in it, and each drop-down is extremely data-heavy.  I'm worried that if the Grid has too many rows and each row's drop-down is full that will make the page too big.
    I was thinking of a solution where each drop-down is empty until, for example, it received focus and then it would be populated by JavaScript from a model so effectively all of the drop-downs will be empty until they receive focus, apart from the models.
    LVL 9

    Assisted Solution

    you add a onclick event for the row or onfocus event . attach a function to the event to load the drop downs with options

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Training Course: Android App Development

    This course will involve creating widgets, customize list view, grid view, spinners, etc. Creating applications using audio, video, and SQLite database. Ending with publication on Google Play.

    Preface This article introduces an authentication and authorization system for a website.  It is understood by the author and the project contributors that there is no such thing as a "one size fits all" system.  That being said, there is a certa…
    Use these top 10 tips to master the art of email signature design. Create an email signature design that will easily wow recipients, promote your brand and highlight your professionalism.
    The viewer will learn the benefit of using external CSS files and the relationship between class and ID selectors. Create your external css file by saving it as style.css then set up your style tags: (CODE) Reference the nav tag and set your prop…
    The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

    758 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    7 Experts available now in Live!

    Get 1:1 Help Now