I'd like to ask for some help. I have an external JSON file with an array inside looking like this:
{ "Files": [
{
"fileName": "Trains",
"fileID": "t1"
},
{
"fileName": "Planes",
"fileID": "p1"
},
{
"fileName": "Cars",
"fileID": "c1"
}
]}
I'm trying to use this data ultimately to fill a dropdown select menu in an XHTML page whilst using JavaScript to write it. So far I've got the following but can't now figure out where I'm going wrong for the final hurdle. Any pointers on what I'm not understanding appreciated, thanks.
function fileDropdown() {
var options = "";
$.getJSON(
"json/files.json",
function(result) {
//find the array and do seomthing
$.each(result.Files, function(key, val) {
options += '<option value="' + val.fileID + '">' + val.fileName + '</option>';
});
}
);
document.write("<select>"+options+"</select>");
}