I have a dropdown list of countries. When one is selected, I need the list of states or provences from that selected country to populate the next dropdown or a text field to be displayed so one can enter a 'region'. I also need to pass the selected country and state or region on to a database. I am not very familiar with javascript, but I understand there is a way to this using javascript. Thanks for any and all help!
here is exactly what you're looking for: http://www.justin-cook.com/wp/2006/...ing-select-menus-client-side-with-javascript/
Hey - Thanks for the direction!! I found a little easier code that is working great: function countryDDChange(c,s){ var evt = document.getElementById(c); var selectedIndex = evt.selectedIndex; //var targetDD = document.getElementById("regionDD") var targetDD = document.getElementById(s) while(targetDD.length > 0){ targetDD.remove(0); } if(evt.options[selectedIndex].value == "Mexico"){ var newElement = document.createElement("option"); newElement.text = "Aguascalientes"; newElement.value = "Aguascalientes"; targetDD.options.add(newElement); }else if(evt.options[selectedIndex].value == "Latin America"){ var newElement = document.createElement("option"); newElement.text = "Columbia"; newElement.value = "Columbia"; targetDD.options.add(newElement); } } Then i call it from the dropdown box: <select name="projectCountry" class="textBox" id="projectCountry" size="1" onChange="countryDDChange('projectCountry','projectState')"> And the dropdown box named 'projectState' is supplied with the states from Mexico or Latin America. Thanks for your help. I hope this helps others.
the problem with that code is that you're hard-coding each option. It's much more maintainable, as well as more efficient to do it with the code I sent, that stores all potential options in arrays
I bet you are right!! But like I said, i am a newbie and this works for now. I have a gut feeling the client will want to add all countries of the world and then I will be very grateful for your code. Wish me luck.