Cascading Dropdown Functionality Using JSON Objects
function loadContent() {
var myJson = [];
var cntry = $('#ctl00_ctl41_g_4715d944_f7f8_411f_90e9_a07c00bb3a42_ff21_ctl00_Lookup option:selected').text();
//var catgry = $('#ctl00_ctl41_g_a7d82431_0602_48f7_a2cd_66063786394c_ff21_ctl00_Lookup option:selected').text();
$().SPServices({
operation : "GetListItems", //Method name
async : false,
//webURL : webUrl,//pass webUrl dynamically
listName : "EmpManualMaster", // List Name
//CAMLQueryOptions : "",
//CAMLViewFields : "<ViewFields><FieldRef Name='Title' /></ViewFields>",
CAMLQuery : '<Query><Where><Eq><FieldRef Name="Country" /><Value Type="Lookup">'+cntry+'</Value></Eq></Where></Query>',
//CAMLRowLimit : 1,
completefunc : function (xData, Status) {
//alert(xData.responseText);
if (xData.status == 200) {
//debugger;
myJson = $(xData.responseXML).SPFilterNode("z:row").SPXmlToJson({
mapping : {
ows_ID : {
mappedName : "ID",
objectType : "Counter"
},
ows_Title : {
mappedName : "Title",
objectType : "Text"
}
}, // name, mappedName, objectType
includeAllAttrs : true
});
//alert(myJson);
} else {
alert(xData.status);
}
}
});
$('#ctl00_ctl41_g_4715d944_f7f8_411f_90e9_a07c00bb3a42_ff31_ctl00_Lookup').empty();
var newOption = $('<option>');
newOption.attr('value', 0).text("(None)");
$('#DropDownList1').append(newOption);
$('#ctl00_ctl41_g_4715d944_f7f8_411f_90e9_a07c00bb3a42_ff31_ctl00_Lookup').append(newOption);
for (var i = 0; i < myJson.length; i++) {
var newOptions = $('<option>');
newOptions.attr('value', myJson[i].ID).text(myJson[i].Title);
$('#DropDownList1').append(newOptions);
$('#ctl00_ctl41_g_4715d944_f7f8_411f_90e9_a07c00bb3a42_ff31_ctl00_Lookup').append(newOptions);
}
//loadContent2();
}
var myJson = [];
var cntry = $('#ctl00_ctl41_g_4715d944_f7f8_411f_90e9_a07c00bb3a42_ff21_ctl00_Lookup option:selected').text();
//var catgry = $('#ctl00_ctl41_g_a7d82431_0602_48f7_a2cd_66063786394c_ff21_ctl00_Lookup option:selected').text();
$().SPServices({
operation : "GetListItems", //Method name
async : false,
//webURL : webUrl,//pass webUrl dynamically
listName : "EmpManualMaster", // List Name
//CAMLQueryOptions : "",
//CAMLViewFields : "<ViewFields><FieldRef Name='Title' /></ViewFields>",
CAMLQuery : '<Query><Where><Eq><FieldRef Name="Country" /><Value Type="Lookup">'+cntry+'</Value></Eq></Where></Query>',
//CAMLRowLimit : 1,
completefunc : function (xData, Status) {
//alert(xData.responseText);
if (xData.status == 200) {
//debugger;
myJson = $(xData.responseXML).SPFilterNode("z:row").SPXmlToJson({
mapping : {
ows_ID : {
mappedName : "ID",
objectType : "Counter"
},
ows_Title : {
mappedName : "Title",
objectType : "Text"
}
}, // name, mappedName, objectType
includeAllAttrs : true
});
//alert(myJson);
} else {
alert(xData.status);
}
}
});
$('#ctl00_ctl41_g_4715d944_f7f8_411f_90e9_a07c00bb3a42_ff31_ctl00_Lookup').empty();
var newOption = $('<option>');
newOption.attr('value', 0).text("(None)");
$('#DropDownList1').append(newOption);
$('#ctl00_ctl41_g_4715d944_f7f8_411f_90e9_a07c00bb3a42_ff31_ctl00_Lookup').append(newOption);
for (var i = 0; i < myJson.length; i++) {
var newOptions = $('<option>');
newOptions.attr('value', myJson[i].ID).text(myJson[i].Title);
$('#DropDownList1').append(newOptions);
$('#ctl00_ctl41_g_4715d944_f7f8_411f_90e9_a07c00bb3a42_ff31_ctl00_Lookup').append(newOptions);
}
//loadContent2();
}
Comments