so I'm a real noob when it comes to javascript. I tried all the solutions here on the site and I checked a few other things from google, but I didn't find anything that worked for me.
I have to create a json array and importat that into a select option list. The goal is to choose music titles from a listbox.
Here's my current html code (if you need more of the code tell me, for now I will just post what I think is necessary):
<td><input id="anzahl" type="number" min="1" max="100"></td>
<td><select id="mySelect" name="Titel">
<option id="01"></option>
<option id="02"></option>
<option id="03"></option>
<option id="04"></option>
<option id="05"></option>
<option id="06"></option>
<option id="07"></option>
<option id="08"></option>
<option id="09"></option>
<option id="10"></option>
</select></td>
...
EDIT: Here's the updated code, but it still doesnt work.
function initSelBox_Product() {
var titelliste= [
{"Produktid":"01","Titel":"Dangerous","Band":"David Guetta","Nettoeinzelpreis":"1.99"},
{"Produktid":"02","Titel":"Sun goes down","Band":"Robin Schulz","Nettoeinzelpreis":"1.99"},
{"Produktid":"03","Titel":"Fade out lines","Band":"The Avener","Nettoeinzelpreis":"1.99"},
{"Produktid":"04","Titel":"Walk","Band":"Kwabs","Nettoeinzelpreis":"1.99"},
{"Produktid":"05","Titel":"Blame","Band":"Calvin Harris","Nettoeinzelpreis":"1.99"},
{"Produktid":"06","Titel":"Geronimo","Band":"Sheppard","Nettoeinzelpreis":"1.99"},
{"Produktid":"07","Titel":"Animals","Band":"Maroon 5","Nettoeinzelpreis":"1.99"},
{"Produktid":"08","Titel":"What are you waiting for?","Band":"Nickelback","Nettoeinzelpreis":"1.99"},
{"Produktid":"09","Titel":"Shake it off","Band":"Taylor Swift","Nettoeinzelpreis":"1.99"},
{"Produktid":"10","Titel":"Chandelier","Band":"Sia","Nettoeinzelpreis":"1.99"} ];
for (var i = 0; i < titelliste.length; i++) {
var select = document.getElementById("mySelect");
var option = document.createElement("option");
option.text = titelliste[i].Titel;
option.value = titelliste[i].Produktid;
select.add(option);
}
}
JSON.parse(titelliste)instead ofeval('(' + titelliste + ')').options[j].Textandoptions[j].Value. Have a look at your array. The objects don't have those properties.