mrperfect75000
asked on
Filter country /state in Javascript
Hi,
I need to create a filter in javascript that will start with country and depending on the country i choose it filters down the states and shows only states in that country and then i want it to filter down to based on state too, so it will show cities in the state based on what state i choose.
I found some script to do this on only one level but it doesnt even work well. anyone knows how i can do this in java script? or is there any where i can find code that does this?
thanks!!
I need to create a filter in javascript that will start with country and depending on the country i choose it filters down the states and shows only states in that country and then i want it to filter down to based on state too, so it will show cities in the state based on what state i choose.
I found some script to do this on only one level but it doesnt even work well. anyone knows how i can do this in java script? or is there any where i can find code that does this?
thanks!!
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
I wanted to add one more thing that that - we have Country, States and Cities. I wanted to add venues to that.
I can do this for the select
<select id="venues" style="width: 150px">
</select>
and i can add a declaration like this in the js
var venuesslist = document.getElementById("v enues");
my problem is now with setting up the array as i want it to filter down all the way from country to venue and also setting up the function
var venues = new Array()
venues[0] = "";
Thanks for your help!! I will add more points for this.
thanks
I can do this for the select
<select id="venues" style="width: 150px">
</select>
and i can add a declaration like this in the js
var venuesslist = document.getElementById("v
my problem is now with setting up the array as i want it to filter down all the way from country to venue and also setting up the function
var venues = new Array()
venues[0] = "";
Thanks for your help!! I will add more points for this.
thanks
like this?
<form>
<select id="countries" onchange="updatestates(thi
<option selected>Select A Country</option>
<option value="usa">USA</option>
<option value="uk">United Kingdom</option>
</select>
<select id="states" onchange="updatecities(thi
</select>
<select id="cities" onchange="updatevenues(thi
</select>
<select id="venues" style="width: 150px">
</select>
</form>
<script type="text/javascript">
<!--
var countrieslist = document.getElementById("c
var stateslist = document.getElementById("s
var citieslist = document.getElementById("c
var venueslist = document.getElementById("v
var states = new Array()
states[0] = "";
states[1] = ["Select A State|", "California|california", "Texas|texas"];
states[2] = ["Select A State|", "Middlesex|middlesex", "Surrey|surrey"];
var cities = new Array()
cities[0] = "";
cities[1] = new Object;
cities[1][0] = "";
cities[1][1] = ["Select A City|", "San Francisco|san_francisco","
cities[1][2] = ["Select A City|", "Dallas|dallas","Houston|h
cities[2] = new Object;
cities[2][0] = "";
cities[2][1] = ["Select A City|", "Teddington|teddington","H
cities[2][2] = ["Select A City|", "Kingston|kingston","Guild
var venues = new Array()
venues[0] = "";
venues[1] = new Object;
venues[1][0] = "";
venues[1][1] = new Object;
venues[1][1][0] = "";
venues[1][1][1] = ["Select A Venue|", "SF 1|sf_1","SF 2|sf_2"];
venues[1][1][2] = ["Select A Venue|", "LA 1|la_1","LA 2|la_2"];
venues[1][2] = new Object;
venues[1][2][0] = "";
venues[1][2][1] = ["Select A Venue|", "D 1|d_1","D 2|D_2"];
venues[1][2][2] = ["Select A Venue|", "H 1|h_1","H 2|h_2"];
venues[2] = new Object;
venues[2][0] = "";
venues[2][1] = new Object;
venues[2][1][0] = "";
venues[2][1][1] = ["Select A Venue|", "T 1|t_1","T 2|t_2"];
venues[2][1][2] = ["Select A Venue|", "H 1|h_1","H 2|h_2"];
venues[2][2] = new Object;
venues[2][2][0] = "";
venues[2][2][1] = "";
venues[2][2][2] = ["Select A Venue|", "K 1|k_1","K 2|k_2"];
venues[2][2][3] = ["Select A Venue|", "G 1|g_1","G 2|g_2"];
var country, state;
function updatestates(selectedcityg
country = selectedcitygroup;
stateslist.options.length = 0;
citieslist.options.length = 0;
if(selectedcitygroup>0){
for(i=0; i<states[selectedcitygroup
stateslist.options[statesl
}
}
}
function updatecities(selectedcityg
citieslist.options.length = 0;
state = selectedcitygroup;
venueslist.options.length = 0;
if(selectedcitygroup>0){
for(i=0; i<cities[country][selected
citieslist.options[citiesl
}
}
}
function updatevenues(selectedcityg
venueslist.options.length = 0;
if(selectedcitygroup>0){
for(i=0; i<venues[country][state][s
venueslist.options[venuesl
}
}
}
//-->
</script>
ASKER
How can i give this person more points?
"How can i give this person more points?"
i'm not sure you can give me more than 500 points, but thank you very much for trying. glad i could help.
i'm not sure you can give me more than 500 points, but thank you very much for trying. glad i could help.
ASKER
Thanks
ASKER