0

I am looking to populate a combo box with a Json file that is representing the file contents of a folder in a directory. I have snippets of code but its obviously not working and I am unsure how to go about implementing it correctly.

My Json code i want to populate the combo box looks like this:

["xml/cdcatalog.xml","xml/equip.xml"]

And this is the script i have embedded into the HTML page:

$(document).ready(function() {
    $("#list1").jCombo(function() {
        $.getJSON('Jsontest.php?q=' + escape($('#list1').val()), function(data) {
            if ($("#list1").val() > 0) {
                alert("You chose " + $("#list1").val());
            }

        });
    });
});
Didier Ghys
  • 30,396
  • 9
  • 75
  • 81
user1199773
  • 3
  • 1
  • 2

1 Answers1

2

I think you want something like this:

$(document).ready(function() { 
   $.getJSON("Jsontest.php", function(result) { 
       var options = $("#list1"); 
       $.each(result, function(item) { 
           options.append($("<option />").val(item).text(item)); 
       }); 
   }); 
});

Code taken from this answer:

jQuery: Best practice to populate drop down?

Community
  • 1
  • 1
Mikey G
  • 3,473
  • 1
  • 22
  • 27