Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

I need a set of Conditional Select Menus Using JQuery (Country, State, County, City)

Posted on 2010-08-20
1
Medium Priority
?
1,089 Views
Last Modified: 2012-05-10
I need a set of HTML Select menus that are conditional on the one above it.  The top level is the Country.  Depending upon the Country, a list of States of Providences need to populate the next menu.  Then a list of Counties in the State or province in the next menu.  Then a list of Cities based on the county.  I already have a US Zipcode database that has all the data.  I just don't know anything about JQuery and need help putting together the elements.

I am in a jam and offer 500 points to whoever can provide me with the needed code.

Phil
0
Comment
Question by:SiriusPhil
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 
LVL 9

Accepted Solution

by:
matthew016 earned 2000 total points
ID: 33489746
You need to bind the event "change" on your select elements.

e.g.

$('select#country').change(function() {
...
}

Each time a select element changes (country, states, etc.), you need to retrieve by AJAX the appropriate sublists and replace those by the old ones.

e.g.
a country has been selected, refresh the <select> states :

$.ajax({
    type: "GET",
    dataType: "json",
    async: false,
    url: "/ajax-get-states?country=" + countrySelected,
    success: function(data){
        $.each(data, function() {
            /* populate the <select> element of states */
            $('<option>').val(this[0]).text(this[1]).appendTo('select#states');
        });
    },
    error: function(xhr, status, ex) {}
});
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction Chart.js, used properly, can visually add a difference to your charting applications. It engages your visitors and allows them to interact with data they otherwise wouldn't be able to without expensive and complicated systems. For this…
How to build a simple, quick and effective accordion menu using just 15 lines of jQuery and 2 css classes
The viewer will learn the basics of jQuery, including how to invoke it on a web page. 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.: (CODE)
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…

604 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