Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

150
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda