JavaScript
  Home arrow JavaScript arrow Dynamically Populating Select Menus Client...
Dev Articles Forums 
ADO.NET  
Apache  
ASP  
ASP.NET  
C#  
C++  
ColdFusion  
COM/COM+  
Delphi-Kylix  
Design Usability  
Development Cycles  
DHTML  
Embedded Tools  
Flash  
Graphic Design  
HTML  
IIS  
Interviews  
Java  
JavaScript  
MySQL  
Oracle  
Photoshop  
PHP  
Reviews  
Ruby-on-Rails  
SQL  
SQL Server  
Style Sheets  
VB.Net  
Visual Basic  
Web Authoring  
Web Services  
Web Standards  
XML  
Dedicated Servers  
Actuate Whitepapers 
Moblin 
IBM® developerWorks 
Sun Developer Network 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
JAVASCRIPT

Dynamically Populating Select Menus Client-Side
By: Justin Cook
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 4 stars4 stars4 stars4 stars4 stars / 16
    2004-06-02

    Table of Contents:
  • Dynamically Populating Select Menus Client-Side
  • Code
  • Function
  • Conclusion

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    ADVERTISEMENT

    Stay one step ahead of the competition. Evaluate and give feedback on some of the hottest web development tools on the market today. Make your opinion heard! Click Here

    Dynamically Populating Select Menus Client-Side


    (Page 1 of 4 )

    We're constantly searching for methods to both improve our application's performance and enhance the user's experience. This little JavaScript tool will enable you to achieve both of those goals. I will show you how to populate a menu of items on the fly, based on the selection of another, without reloading the page. This is handy for search tools, registration forms, inventory programs, and so many others. Just have a read, and you'll find a place for it in your own application!


    To start off with, I'd just like to advise you to not be fooled by the title. Just because you see the phrase 'client-side' in there doesn't mean that you ASP/PHP buffs can quickly navigate to another article. Well, truthfully you can, but you shouldn't! Once you understand the reasoning behind this article, you'll truly appreciate how even a bit of JavaScript can enhance the usability your application ten fold. This code could be employed on a static page, but I'm going to deal primarily with dynamic pages, because that's probably where you'll get the most use of it.

    I feel I need to explain exactly what it is this little magic trick does. Picture a registration form, one where you have to input your country and state/province of residence. What if the form could give you a menu of selectable countries, and then generate another for you listing the logically available states/provinces to choose from. This would eliminate the need for users to type in their state/province, and also prevent them from having to scroll through one massive list of all possible states/provinces in all countries.

    Now you're already thinking that this can be done server-side. We could simply reload the page when the first menu changes (user selects a country), and populate the second menu with items associated with the selected item of the first. While this is all well and good, this requires another hit to the server and trip to the database, thus slowing things down for everyone. If we can push this piece of processing off to the client's browser, why not do it?

    Another example could be in the search form of an e-commerce website. A user selects from a list of categories that they're looking for a laptop, and immediately the next menu allows them to select from the possible manufacturers that you stock. Now are you starting to see the usefulness of this? If so, continue to read on, I'll show you how it's done.

    More JavaScript Articles
    More By Justin Cook


     

    JAVASCRIPT ARTICLES

    - Detect Browser Compatibility with the Reques...
    - Using the EXT JS Date Picker Widget
    - Ajax Hack for Entering Information Without R...
    - EXT JS 2.1 Overview
    - Using the Style Object for Zebra Tables with...
    - Binary Searching
    - An Improved Approach to Building Zebra Tables
    - Assigning Background Colors Dynamically to Z...
    - Building Zebra Tables with CSS and JavaScript
    - JavaScript: Array Objects
    - A Closer Look at Smart Markers with Yahoo! M...
    - Using Polylines and Smart Markers with Yahoo...
    - Bulleted Menu of Links
    - Creating Click Loggers and Basic Markers wit...
    - Adding Pan Controls to Yahoo! Maps







    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 6 hosted by Hostway