so i have json array
data = '[{"beatles": [
{"name":"Paul McCartney","value": "http://www.paulmccartney.com"},
{"name": "John Lennon","value": "http://www.johnlennon.it"},
{"name":"George Harrison","value": "http://www.georgeharrison.com"},
{"name": "Ringo Starr","value": "http://www.ringostarr.com"}],
"stones": [
{"name": "Mick Jagger","value": "http://www.mickjagger.com"},
{"name": "Keith Richards","value": "http://www.keithrichards.com"}]'
and i have two dropdown lists
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title></title>
<script src="rockbands.json"></script>
<script src="script.js"></script>
</head>
<body onload="getBands()">
<select id="bands" onchange="getNames(this.value)"></select>
<select id="names" ></select>
</body>
</html>
so i load the dropdownlist with ID "bands" with this JS Code
function getBands() {
var root = JSON.parse(data)
var bandsBox = document.getElementById("bands")
for(i in root[0]) {
var option = document.createElement("option")
option.text = i
bandsBox.appendChild(option)
}
}
what i want to do is populate the other dropdown list with ID "names" with the array element "name" based on the selection in the first dropdownlist for example if i chose beatles it would load all names in beatles
i could access it with something like root[0].beatles[1].name but i want a dynamic way to access them thanks