Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

143
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!