Вариант ... если у кого будет желание может распихать по файлам
<!DOCTYPE HTML>
<html>
<head>
<title></title>
<meta charset="windows-1251" />
<script>
window.onload = function () {
var country = {
'ID': [1, 2, 3],
'name': ['Россия', 'Украина', 'Эстония'],
'url': ['rossia', 'shvecia', 'polsha']
},
city = {
'ID': [1, 2, 3, 4, 5, 6],
'id_country': [1, 1, 2, 2, 3, 3],
'name': ['Санкт-Петербург', 'Москва', 'Киев', 'Харьков', 'Таллин', 'Нарва'],
'url': ['spb', 'moscow', 'kiev', 'kharkov', 'tallinn', 'narva']
}
function set_select(name, arr_text, arr_val) {
var select = document.getElementsByName(name)[0];
select.options.length = 0;
for (var k = 0; k < arr_val.length; k++) {
select.options[k] = new Option(arr_text[k], arr_val[k]);
}
}
var select = document.getElementsByName('country')[0];
function change_select() {
var j = select.selectedIndex || 0,
name = [],
url = [];
j = country['ID'][j]
for (var i = 0; i < city['id_country'].length; i++) {
if (city['id_country'][i] == j) {
name.push(city['name'][i]);
url.push(city['url'][i]);
}
}
set_select('city', name, url)
}
set_select('country', country['name'], country['url'])
change_select()
select.addEventListener('change', change_select);
}
</script>
</head>
<body>
<select name="country">
</select>
<select name="city">
</select>
</body>
</html>