Boa tarde, Estou utilizando uma função para carregar meu combo, de acordo com a seleção de outro combo. Entretanto, está carregando duas vezes a primeira opção. Segue abaixo o código: function alteraGrupoCliente() {
GeraLista(document.getElementById('SelCGCod'), document.getElementById('CGCodLista'));
GeraLista(document.getElementById('SelDGCod'), document.getElementById('DGCodLista'));
GeraLista(document.getElementById('SelDistCod'), document.getElementById('DistCodLista'));
var vFiltro1 = "";
var vFiltro2 = "";
var vFiltro = "";
if (document.frmCampos.CGCodLista.value != 0) {
vFiltro1 = " And DGCod in (Select DGCod From Distribuidores D Where DistCod in (Select DistCod From Distribuidores_Clientes DC Where CliCod in (Select CliCod From Clientes where CGCod in (0" + document.frmCampos.CGCodLista.value + ") or CGCod is null)))";
vFiltro2 = " And DistCod in (Select DistCod From Distribuidores_Clientes Where CliCod in (Select C.CliCod From Clientes C where C.CGCod in (0" + document.frmCampos.CGCodLista.value + ") or CGCod is null))";
}
if (document.frmCampos.DGCodLista.value != 0) {
vFiltro = " And DGCod in (0" + document.frmCampos.DGCodLista.value + ") or DGCod is null ";
}
preencheCombo(document.getElementById("DistCod"), "Distinct D.DistCod,DistNome ", "Distribuidores D", "ISNULL(DistAtivo,1)", " 1 ", " ISNULL(DistAtivo,1) <> 0 " + vFiltro + vFiltro2, "DistNome ASC")
preencheCombo(document.getElementById("DGCod"), "D.DGCod,DGNome ", "DistribuidoresGrupos D", "ISNULL(DGAtivo,1)", " 1 ", " ISNULL(DGAtivo,1) <> 0 " + vFiltro1, "DGNome ASC")
}
function alteraGrupoDistribuidores() {
GeraLista(document.getElementById('SelDGCod'), document.getElementById('DGCodLista'));
var vFiltro = "";
if (document.frmCampos.DGCodLista.value != 0) {
vFiltro = " And DGCod in (0" + document.frmCampos.DGCodLista.value + ") or DGCod is null ";
}
preencheCombo(document.getElementById("DistCod"), "Distinct D.DistCod,DistNome ", "Distribuidores D", "ISNULL(DistAtivo,1)", " 1 ", " ISNULL(DistAtivo,1) <> 0 " + vFiltro, "DistNome ASC")
}
function preencheCombo(pCombo,pCampos,pOrigem,pChave,pValorChave,pFiltro,pSelecionado,pOrdem) {
vCampoOrdem = (pOrdem==undefined?"2":pOrdem);
pFiltro = (pFiltro==undefined?"":pFiltro);
pSelecionado = (pSelecionado==undefined?0:pSelecionado);
var vURL = "RetornaCampo.asp?Campo=" + pCampos
+ "&Tabela=" + pOrigem
+ "&Chave=" + escape(pChave)
+ "&FiltroAdicional=" + pFiltro
+ "&Limite=não"
+ "&Filtro=" + escape(pValorChave)
+ "&Ordem=" + vCampoOrdem;
alert(vURL);
var strRetorno = executaURL(vURL);
if ((strRetorno.indexOf("Error") != -1) || (strRetorno.indexOf("OLE DB Provider") != -1) || (strRetorno.indexOf("SQL Native Client") != -1)) {
alert(strRetorno);
}
pCombo.options.length = 1;
if (strRetorno != "" ) {
strRetorno = aplicarAcentuacao(strRetorno);
var arLista = strRetorno.split("\r\n");
var indSel = 0;
for (var j=0; j<arLista.length; j++){
var arValores = arLista[j].split("#$#");
pCombo.options[j+1] = new Option(arValores[1], arValores[0]);
if (pSelecionado == arValores[0]) {
indSel = j+1;
}
}
}
pCombo.selectedIndex = indSel;
}
function GeraLista(obOrigem, obDestino){
var i;
obDestino.value = "";
for (i=0; i < obOrigem.length; i++){
obDestino.value = obDestino.value + obOrigem.options[i].value;
if (i + 1 < obOrigem.length){
obDestino.value = obDestino.value + ",";
}
}
}