I am trying to fill this HTML Select
<select id="list">
</select>
With data from JSON (the actual JSON contains more keys and values than shown below):
{"Group1": "TestGroup1", "Group2" : "TestGroup2" "TotGroups" : "2"}
Using JQuery and AJAX to fetch the data. AJAX Success response:
success: function(resp) {
var json_obj = $.parseJSON(resp);
for (i=1, x=json_obj.TotGroups; i <= x; i++) {
$('#list').append('<option>'+json_obj.Group1+' </option>');
}
As you can see this only appends the data from json_obj.Group1. What I want is everytime the loop runs, append one group at a time, first Group 1, then Group 2, until TotGroups is reached (in this case 2).
Any ideas? :)
UPDATE: SOLVED
$('#list').append('<option>'+json_obj["Group" + i]+' </option>');