Solved

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

Posted on 2010-08-20
1
1,087 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 500 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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Recently while working on a project I got a very annoying cfdocument has no body error message. I had never seen this error before. So I checked the code. The code was pretty simple; it was Just showing me the cfdocumnt tag and inside that tag a …
PROBLEM: The other day I was working on adding an ajax request to a webpage that already had a dialog box on the page.  The dialog box was using relative positioning to be positioned next to a form field I had on the page.  Everything was working…
The viewer will learn how to dynamically set the form action using jQuery.
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…

687 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