iam newbie here.. please execuse if iam asking wrong question here.
iam developing dynamic page having two drop down boxes in which second automatically refreshed based on selection of value from first drop down.iam using jquery $.html to automatically refresh second drop down.
$("#subcategory").html('<select name="sub_category" class="valid" id="subcategory"><option>Art - Classes</option><option>Beautician Courses</option><option>Computer - Multimedia Classes</option><option>Cooking - Classes</option><option>Hobby - Classes</option><option>Language Classes</option><option>Motor driving - Classes</option><option>Music - Theatre - Dance Classes</option><option>Professional courses - tutions</option><option>Summer - Camps</option><option>Training Instutions</option><option>Tutoring - Private Lessons</option><option>Other Classes</option></select>').show();
instead of above one i would like to try with json object and populate second drop down.
my json data will be as below:
var data = {
cat_1: {
{"id": "1",
"sub_cat": "sub1"},
{"id":"2",
"sub_cat":"sub2"}
},
cat_2: {
{"id": "3",
"sub_cat": "sub3"},
{"id":"4",
"sub_cat":"sub4"}
}
};
if user selects category 1 second drop down should populate value from cat_1.
iam using below code. but i dont know where to restrict or filter based on selection from first drop down
$.each(data, function(index, array,array1) {
// options[options.length] = new Option(array['variety']);
options[options.length] =new Option(array['id'],array['sub_cat']);
1 Answer