<!doctype html>
<html lang="en">
<head>
<script>
document.addEventListener('DOMContentLoaded', init_select, false);
function init_select() {
let dict_region_city = [{
'id': 1,
'name': 'region1',
'cities': [{
'id': 1,
'name': 'city1'
}, {
'id': 2,
'name': 'city2'
}, {
'id': 3,
'name': 'city3'
}, ]
}, {
'id': 2,
'name': 'region2',
'cities': [{
'id': 4,
'name': 'city4'
}, {
'id': 5,
'name': 'city5'
}, {
'id': 6,
'name': 'city6'
}, ]
}, ];
let sel_region_cont = document.getElementById("sel_region_cont");
let sel_city_cont = document.getElementById("sel_city_cont");
let sel_region = document.createElement("select");
sel_region.id = "sel_region";
sel_region.name = 'sel_region';
sel_region_cont.appendChild(sel_region);
sel_region.appendChild(document.createElement("option"));
for (let i = 0; i < dict_region_city.length; i++) {
let option = document.createElement("option");
option.value = dict_region_city[i].id;
option.text = dict_region_city[i].name;
sel_region.appendChild(option);
}
// end init
sel_region.addEventListener('change', recreate_city_select_onchange);
function recreate_city_select_onchange() {
let sel_region_item = event.srcElement.options[event.srcElement.selectedIndex];
let cities_dict;
for (let i = 0; i < dict_region_city.length; i++) {
if (sel_region_item.value == dict_region_city[i].id) {
cities_dict = dict_region_city[i].cities;
break;
}
}
sel_city_cont.innerHTML = '';
if (cities_dict) {
let sel_city = sel_city_cont.appendChild(document.createElement("select"));
for (let i = 0; i < cities_dict.length; i++) {
let option = document.createElement("option");
option.value = cities_dict[i].id;
option.text = cities_dict[i].name
sel_city.appendChild(option);
}
sel_city.addEventListener("change", action_on_change_city_sellector);
}
function action_on_change_city_sellector() {
let sel_city_item = event.srcElement.options[event.srcElement.selectedIndex];
console.log(sel_city_item)
// do code here
}
}
}
</script>
</head>
<body>
<div id="sel_region_cont"></div>
<div id="sel_city_cont"></div>
</body>
</html>
Теперь подведите под один из пунктов
Но насколько я понимаю, то шанс апрува минимален
https://www.xda-developers.com/google-play-develop...