I want to fill a list with elements from a database. The data comes from a PHP file in JSON format. The JSON looks like this:
{"Venues" : [{"name":"McManus Galleries","id":"1"},{"name":"Dundee Law","id":"2"},{"name":"University of Abertay","id":"3"},{"name":"Baxter Park","id":"4"},{"name":"Overgate Shopping Centre","id":"5"}]}
Now I am handling this text with the following code:
obj = JSON.parse(this.responseText);
document.getElementById("list").innerHTML = "<a onclick='getVenue("+obj.Venues[0].id + ")'>" + obj.Venues[0].name + "</a><br>";
document.getElementById("list").innerHTML += "<a onclick='getVenue("+obj.Venues[1].id + ")'>" + obj.Venues[1].name + "</a><br>";
...and it works, but now I want to do it with a for-loop so no matter how many items "Venues" contains it is showing them all in the list. I got this code right now:
for(i = 0; i < obj.length; i++){
document.getElementById("list").innerHTML += obj.Venues[i].name;
}
The problem here is, that obj.length returns 1. Does anybody know how to solve this?
obj.Venues.length.obj.Venues, notobj.