I have first drop down list ddl1 which contains these values:
- Car
- Van
and the second drop down list ddl2 contains:
- Car Honda
- Car BMW
- Van Golf
I need a script that filters the second ddl for example when I choose Car, the second ddl should only show these two fields:
Car Honda
– Car BMW
My code:
<script type="text/javascript">
function Filter(){
var names = $('#typeCar option').clone();
$('#Type').change(function(){
var val = $(this).val();
$('#typeCar').empty();
names.filter(function(idx, el){
return val === 'ALL' || $(el).text().indexOf(val) >= 0;
}).appendTo('#typeCar');
});
}
</script>
you will want something like this:
Each List Item value in the second list should start with the same value of the item in the first list. This is so it can be filtered by the value of the first.
EDIT:
Items in drop downs.
List 1:
List 2:
Javascript: