Skip to content

Instantly share code, notes, and snippets.

@Sleepful
Created June 8, 2015 17:08
Show Gist options
  • Save Sleepful/dd3c678ed5dc0ab51ba1 to your computer and use it in GitHub Desktop.
Save Sleepful/dd3c678ed5dc0ab51ba1 to your computer and use it in GitHub Desktop.
//______________________CLASE____________________//
var urlOrden = '@Url.Action("getOrden", "Account")';
var avesOrden = $('#Orden'); // caches element from a @html.dropdownlist in the HTML
$('#Clase').change(function () {
onchangeClase($(this).val());
//if i place onchangeSuborden("") here it doesnt work well
});
function onchangeClase(val) {
$.getJSON(urlOrden, { idClaseIN: val }, function (lista_result) { //calls a function on the server to retrieve info from database
// code to repopulate the list in an already existing dropdownlist(this uses the database info):
avesOrden.empty().append($('<option></option>').val('').text('Orden'));
$.each(lista_result, function (index, item) {
avesOrden.append($('<option></option>').val(item.Value).text(item.Text));
});
onchangeSuborden(""); //it works when i place it here
});
//if i place onchangeSuborden("") here it doesnt work well either
}
//______________________SUBORDEN____________________//
var urlSuborden = '@Url.Action("getSuborden", "Account")';
var avesSuborden = $('#Suborden');
$('#Orden').change(function () {
onchangeSuborden($(this).val());
});
function onchangeSuborden(val) {
$.getJSON(urlSuborden, { idOrdenIN: val }, function (lista_result) {
avesSuborden.empty().append($('<option></option>').val('').text('Suborden'));
$.each(lista_result, function (index, item) {
avesSuborden.append($('<option></option>').val(item.Value).text(item.Text));
});
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment