Here is the json. Im displaying year and make in a select box. When i select an year and make its related data should filter and display in a grid.For eg when i select 2010 and def the related data i.e,2010. def, 300 & 5000 should be displayed in the grid. Can any one help me to do this with out using any jquery plugins.
var data = [
{ Year: "2011", Make: "abc", Model: "100", SubModel: "5000", },
{ Year: "2011", Make: "abc", Model: "200", SubModel: "6000", },
{ Year: "2010", Make: "def", Model: "300", SubModel: "5000", },
{ Year: "2011", Make: "def", Model: "100", SubModel: "1000", }
];
Here is my code: http://jsfiddle.net/qK2A3/2/
Ans to my ques
function getRelated() {
$.each(g_Vehicle, function (index) {
var sMake = g_Vehicle[index].Make;
if (g_Vehicle[index].Make == $('#DropDown_Make').val() && g_Vehicle[index].Year == $('#DropDown_Year').val()) {
$(".ModelClass").html(g_Vehicle[index].Model);
$(".SubModelClass").html(g_Vehicle[index].SubModel);
}
});
};
DEMO: http://jsfiddle.net/ybT7a/ It's working.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With