I am trying to fill the second selector based on the first selector.
My goal is to add all the titles of tracks that are under the artist that is selected.
What is going wrong is that if I put artistValue in console log I get the right value but if I use it to sort on the artist for getting tracks I get this error Cannot convert undefined or null to object
My HTML
<select onchange="Update()" id="artistSelector"></select>
<select id="trackSelector"></select>
My Javascript
// Get json file
const url = './jukebox.json';
const request = new XMLHttpRequest();
request.open('GET', url, true);
// activates when the first selector value is changed / onchange="Update()"
function Update() {
// Gives value Krezip or Cure but can have more options in the future.
let artistValue = document.getElementById("artistSelector").value;
const select = document.querySelector('#trackSelector');
const data = JSON.parse(request.responseText);
const entries = Object.entries(data.Albums[artistValue].tracks.title);
for (const [tracks] of entries) {
const option = document.createElement('option');
option.textContent = artist;
option.value = artist;
select.appendChild(option);
}
}
My JSON
{
"Albums": {
"Krezip": [
{
"artist":"Krezip",
"tracks": [
{
"title":"Lost without you",
},
{
"title":"I would stay",
}
]
}
],
"Cure": [
{
"artist":"The Cure",
"tracks": [
{
"title":"A Forest",
},
{
"title":"Lullaby",
}
]
}
]
}
}