If you have pairing defined, you can use mapping method:
var map = new Object(); // or var map = {};
map[myKey1] = "subCat1,subCat2";
map[myKey2] = "subCat3,subCat4";
function get(k) {
return map[k];
}
//Attach event with dropdown selector, of main category.
$("#categorySelectorId").change(function(){
var subCategory = $("#subCategorySelectId");
subCategory.find('option').remove().end(); // To clear previous items
var mappedValue = get(this.value); // to get all mapped items
var subCategories = mappedValue.split(',');
$.each(subCategories, function() { // populate sub category items
options.append($("<option />").val(this.text).text(this.text));
});
});