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  
Mobile Linux 
App Generation ROI 
IBM® developerWorks 
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 / 18
    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


    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

    - Validating Digits and Dates with jQuery`s Va...
    - Validating Ranges, Emails, and URLs with jQu...
    - More Uses for the jQuery Tooltip Plug-in`s b...
    - Building Image-Based Tooltips with the jQuer...
    - Using the jQuery Tooltip Plug-in`s bodyHandl...
    - Using Rangelength, Min and Max with the Vali...
    - Using Minlength and Maxlength with the Valid...
    - Modifying Tooltip Coordinates with the jQuer...
    - Applying a Fade Out Effect with the jQuery T...
    - Tracking Mouse Movements with the jQuery Too...
    - Checking Online Forms with the Validator jQu...
    - Nested JavaScript Functions as Objects
    - The jQuery Tooltip Plug-in
    - Active Client Pages at the Server
    - ACP Tab Web Page







    © 2003-2009 by Developer Shed. All rights reserved. DS Cluster 6 Hosted by Hostway
    Stay green...Green IT