Reputation: 616
How can i filter the "Make" values according to the year. For eg: When i select "Year" as "2012" the related data i.e; only "def" should be displayed in the drop down box. Another problem is the previous data in the table was shown again when i select next values. See the demo for better understanding.
I tried this.
$.each(g_Vehicle, function(index) {
var sMake = g_Vehicle[index].Make;
if($('#DropDown_Year').val())=='2011'){ /* for testing purpose i give year as 2011*/
if ($.inArray(sMake, g_MakesArray) == -1) {
g_MakesArray.push(sMake);
}
}
});
Upvotes: 1
Views: 1156
Reputation: 117
I would use grep for this
e.g.
var newArray = jQuery.grep(g_Vehicle , function(element, index){
return element.Make == "abc" ;
});
Upvotes: 0
Reputation: 4557
To filter a collection/array use the $.grep, to know more about this take a look at the jqfaq.com article, this will explain more on this.
Upvotes: 3
Reputation: 475
function filter() {
switch($(this).text()) {
case "2012":
//filter logic
$("#dropdown2").html("<select>....</select><select>...</select>");
break;
....
}
}
$("#dropdown").change(filter);
You can make the second drop box empty when start and fill it with appropriate selects after someone selects year.
Upvotes: 0