Click here to Skip to main content
15,881,789 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Iam Using JqGrid to show the values

While editing the detials , I need to show cascading values in selectbox in popup.

I tried by using edit options URL and build select, but Iam not able to know how to set cascading based on previous values.

I need to do it using database, not local data.

On change its working fine, I need the same initially displaying the popup

What I have tried:

editoptions: {
dataUrl: $("#ZoneMaster_GetDistricts").val(),
dataInit: function (elem) {
$(elem).width(165);
},
buildSelect: function (data) {
var response = jQuery.parseJSON(data);
var s = '<select>';
for (var i = 0; i < response.length; i++) {
s += '<option value="' + response[i]["DistrictId"] + '">' + response[i]["DistrictName"] + '</option>';
}
return s + "</select>";

},
Posted
Updated 25-Oct-16 23:46pm

1 solution

jQuery(function($) {
var locations = {
'Germany': ['Duesseldorf', 'Leinfelden-Echterdingen', 'Eschborn'],
'Spain': ['Barcelona'],
'Hungary': ['Pecs'],
'USA': ['Downers Grove'],
'Mexico': ['Puebla'],
'South Africa': ['Midrand'],
'China': ['Beijing'],
'Russia': ['St. Petersburg'],
}

var $locations = $('#location');
$('#country').change(function () {
var country = $(this).val(), lcns = locations[country] || [];

var html = $.map(lcns, function(lcn){
return '<option value="' + lcn + '">' + lcn + '</option>'
}).join('');
$locations.html(html)
});
});

See this demo link:
SO - 18351921 - JSFiddle[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900