Created
October 24, 2016 01:36
-
-
Save claudiohilario/a714ab13ddd4d3a77dee9d0cbf515a4b to your computer and use it in GitHub Desktop.
Dropdownlist Matrialize JQuery
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** Carrega os distritos para o Dropdownlist */ | |
$.ajax({ | |
url:'<?=base_url('pedidos_ajax/getDistritos')?>', | |
type: 'post', | |
dataType:'json', | |
data: {<?= $this->security->get_csrf_token_name(); ?>:token_chave}, | |
success: function (resposta) { | |
var listaOpcoes= '<option value="" disabled selected>Escolha o Distrito</option>'; | |
var dadosJSON = resposta.dados; | |
for (var i = 0; i < dadosJSON.length; i++){ | |
listaOpcoes+= "<option value='" + dadosJSON[i].CodigoDistrito + "'>" + dadosJSON[i].Designacao + "</option>"; | |
} | |
//Carregamento da lista de Concelhos | |
$('#ListaDistritos').html(listaOpcoes); | |
$('#ListaDistritos').material_select(); | |
token_chave = resposta.token; | |
} | |
}); | |
/** Ao clicar em um Distrito */ | |
$('#ListaDistritos').on('change', function() { | |
//Guarda o value na variavel | |
var DistritoSelecionado = $("#ListaDistritos").prop('selectedIndex'); | |
//Carrega os concelhos para a Dropdownlist dos concelhos | |
$.ajax({ | |
url:'<?=base_url('pedidos_ajax/getConcelhos')?>', | |
type:'post', | |
dataType:'json', | |
data: {<?= $this->security->get_csrf_token_name(); ?>: token_chave, funcao:'Concelhos', id_distrito:DistritoSelecionado}, | |
success: function (resposta) { | |
var listaOpcoes= '<option value="" disabled selected>Escolha o Concelho</option>'; | |
var dadosJSON = resposta.dados; | |
for (var i = 0; i < dadosJSON.length; i++){ | |
listaOpcoes+= "<option value='" + dadosJSON[i].CodigoConcelho + "'>" + dadosJSON[i].Designacao + "</option>"; | |
} | |
//Carregamento da lista de Concelhos | |
$('#ListaConcelhos').html(listaOpcoes); | |
$('#ListaConcelhos').material_select(); | |
token_chave = resposta.token; | |
} | |
}); | |
$("#ListaConcelhos").prop('disabled',false); | |
$('#ListaConcelhos').material_select(); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment