OK I spent spent a lot of time looking over examples but can\'t find one which helps me enough for my situation. I have a JSON file, simplified for this example:
<
Try something like this. You should really have a value property for your options. I added a data-id attr to the options so I can use that to store the index of Position.
$.each(data.Company, function(i, v) {
// create option with value as index - makes it easier to access on change
var options = $('', {value: v.Position, text: v.Position}).attr('data-id',i);
// append the options to job selectbox
$('#job').append(options);
});
// bind change event
$('#job').change(function() {
// cache this
var $el = $(this);
// get data-id attr from selected option
var id = $('option:selected',this).data('id');
// empty select
$('#name').empty();
// get name values for selected option
$.each(data.Company[id].Name, function(i, v) {
// create option elements
var options = $('', {value: v, text: v});
// append the options to name selectbox
$('#name').append(options);
});
}).change();// trigger change() on page load to fill name selectbox
http://jsfiddle.net/wirey00/xYX8z/