var dyn_carsOptionTree = [['34',[['i40','2191'],['Santa Fe','309']]],['51',[['Mazda3','925']]],['63',[['Astra','868']]],['78',[['Alhambra','669'],['Ateca','2589'],['Ibiza','672'],['Leon','673'],['Toledo','676']]],['80',[['Fabia','679'],['Kodiaq','2607'],['Octavia','682'],['Rapid','2364'],['Superb','683']]],['88',[['Avensis','726']]],['93',[['Golf','812'],['Polo','819']]],['94',[['S60','847']]]]; var yearsTree = {"80":{"683":["2016","2014","2017","2013","2010"],"682":["2017","2015","2016","2010","2013","2014","2011"],"2364":["2015","2014","2013"],"2607":["2017"],"679":["2017","2011"]},"78":{"673":["2016","2017"],"676":["2015"],"672":["2017","2014"],"2589":["2017"],"669":["2017"]},"51":{"925":["2014"]},"94":{"847":["2011"]},"88":{"726":["2009"]},"93":{"819":["2017"],"812":["2013"]},"34":{"309":["2014"],"2191":["2013"]},"63":{"868":["2014"]}}; var yearsDefault = ["2017","2016","2015","2014","2013","2011","2010","2009"]; function populateTarget(name,triggerObj,targetObj,emptyText) { eval ('tree = ' + name + 'OptionTree') triggerValue = getValue(triggerObj) for (i=0;i -1) value = formObj.options[formObj.selectedIndex].value } else { if (formObj.length) { // radio for (var b = 0; b < formObj.length; b++) if (formObj[b].checked) value = formObj[b].value } else if (formObj.checked) // checkbox value = formObj.value } return value } $(document).ready(function() { $('#make_id').change(function() { var year_options_html = '', year_options = [], make_id = $(this).val(); if (make_id != '') { $.each(yearsTree[make_id], function(index, value) { $.each(value, function (index2, value2) { if (year_options.indexOf(value2) == -1) { year_options.push(value2); } }); }); } else { year_options = yearsDefault; } year_options = year_options.sort().reverse(); $.each(year_options, function(index, value) { year_options_html += ''; }); $('#reg_year').html(year_options_html); }); $('#model_id').change(function() { var make_id = $('#make_id').val(), model_id = $(this).val(), year_options_html = '', year_options = []; if (model_id != '') { $.each(yearsTree[make_id][model_id], function(index, value) { if (year_options.indexOf(value) == -1) { year_options.push(value); } }); year_options = year_options.sort().reverse(); $.each(year_options, function(index, value) { year_options_html += ''; }); $('#reg_year').html(year_options_html); } else { $('#make_id').change(); // initialize make years } }); });