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

151
Visualizações
AngularJS days dropdown does not update when month dropdown changes

I am working on DOB validation in AngularJS. However I am facing an issue. Whenever I'm changing the month from the dropdown, the days dropdown won't get updated on the first click of the dropdown. So technically, I have to select first a random number of the days dropdown, only then the number of days will get updated on the second click, depending on the selected month. The days array is updating after the clicking any month in dropdown, but it is not updating the days in days dropdown. Sharing this code snippet. Any advice? Thanks.

$(document).ready(function () {
$('#monthOfBirth').change(function () {

var e = document.getElementById('monthOfBirth');
var monthValue = e.options[e.selectedIndex].value;
var monthLength = [31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];

var setNumberOfDays = monthLength[monthValue - 1];
console.log(monthValue, setNumberOfDays);

function populateDays() {
  const days = [];
  for (let i = 1; i <= setNumberOfDays; i += 1) { //
    if (i < 10) {
      days.push({ value: `0${i}`, text: `0${i}` });
    } else {
      days.push({ value: i, text: i });
    }
  }
  return days;
}
function populateMonths() {
  const months = [];
  for (let i = 1; i <= 12; i += 1) {
    if (i < 10) {
      months.push({ value: `0${i}`, text: `0${i}` });
    } else {
      months.push({ value: i, text: i });
    }
  }
  return months;
}
function populateYears() {
  const years = [];
  for (let i = 1950; i <= new Date().getFullYear(); i += 1) {
    years.push({ value: i, text: i });
  }
  return years;
}

$scope.dayOfBirth_items = populateDays();
$scope.monthOfBirth_items = populateMonths();
$scope.yearOfBirth_items = populateYears();

}); })

about 4 years ago · Santiago Gelvez
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