I am trying to load values into a select dynamically using values from a json string.
The data is being loaded correctly, but for some reason, only the 1st value is loading into the select. Can anyone spot why this could be?
Here is my JSON data:
[{"cat_id":"1","cat_section":"pages","cat_type":"cat","cat_name":"Music","cat_order":"1","cat_parent_id":"0"},{"cat_id":"2","cat_section":"pages","cat_type":"cat","cat_name":"Arts & Culture","cat_order":"2","cat_parent_id":"0"},{"cat_id":"3","cat_section":"pages","cat_type":"cat","cat_name":"Travel & Escape","cat_order":"3","cat_parent_id":"0"},{"cat_id":"4","cat_section":"pages","cat_type":"cat","cat_name":"Technology","cat_order":"4","cat_parent_id":"0"}]
An here is my jQuery:
$("select#select_category").change(function(){
$.getJSON("<?php echo site_url()?>ajax/categories/pages/" + $(this).val(), function(data){
var options = '';
for (var i = 0; i < data.length; data++) {
options += '<option value="' + data[i].cat_id + '">' + data[i].cat_name + '</option>';
}
$("select#select_subcategory").html(options);
})
});