Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

144
Visualizações
How do I pass id from function into the promise.all in jQuery?

I want to pass id of previous selected value into another select function. I have 3 select menu that are dependent to each other. Example

user have to select the State first than , district after that they can select the city value.

With this code I got error of Uncaught ReferenceError: a is not defined How to solve this ?

This is what I have tried

$(document).ready(function() {
  $("#state").change(function() {
    let state = $(this).val();
    getDistrict(state);
  });


  $("#district").change(function() {
    let district = $(this).val();
    getCity(district);
  });

});

function getStateList() {
  return axios.get(`${url}state`);
}

function getDistrict(state) {
  return axios.get(`${url}dist?state_id=${state}`);
}

function getCity(district) {
  return axios.get(`${url}city?district_id=${district}`);
}



about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

The problem is, that a and b aren´t declared. You can use the var state to call getDistrict, because you use it in the enviroment of your function.

If you want to access state as a and district as b, you need to declare them outside of your functions. This could be something like this:

var a;
var b;

$(document).ready(function() {
  $("#state").change(function() {
    a = $(this).val();
    getDistrict(a);
  });


  $("#district").change(function() {
    b = $(this).val();
    getCity(b);
  });

});

function getStateList() {
  return axios.get(`${url}state`);
}

function getDistrict(state) {
  return axios.get(`${url}dist?state_id=${state}`);
}

function getCity(district) {
  return axios.get(`${url}city?district_id=${district}`);
}


Promise.all([getStateList(), getDistrict(a), getCity(b)])
  .then(function(results) {
//code
});
about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda