I'm trying to retrieve an array value where the key is a variable. JSFiddle here -- type 'apparel' or 'books' into the industry input. The output of the JSFiddle states that the value returned is undefined.
The problem lies in var filename = constants.factsheet - how can I correctly pass the value of factsheet to retrieve the associated filename?
JS:
$(function () {
var availableIndustries = ["apparel", "books"];
$("#industry").autocomplete({
source: availableIndustries
});
$("input[type=image]")
.button()
.click(function (event) {
var constants = {
'apparel': 'apparel.pdf',
'books': 'publishing.pdf',
};
var factsheet = document.getElementById('industry').value;
var filename = constants.factsheet;
$('#factsheet').text('Your factsheet is ' + factsheet);
$('#file').text('Your filename is ' + filename);
});
});