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

255
Visualizações
How to set the right value as selected after populating multiple dropdowns?

As the title says, I'm trying to update dropdowns I've populated on a timesheet with jQuery every time I load my table. So there are like 28-31 days and each day has its own dropdown with id="dayType1" all the way up to 31. I was hoping there is a way to iterate on the jQuery selector but from what I read it is not possible? I tried to put each time it runs over the iteration a new ID together like a string and then paste it into the function as a selector, but that doesn't seem to work either. So now I call upon the jQuery gods here to help this peasant. :)

I keep the values for the dropdowns in a separate list so as the iteration goes the list has the values that I need to change the dropdowns to in order at the same spot. (So dropdown 8 needs to be set as the integer saved in the list on the 8th spot.)

First I had timesheets of only a week and could do this:

function setDayTypes() {
    $('#dayType1').val(dayTypeList[0]);
    $('#dayType2').val(dayTypeList[1]);
    $('#dayType3').val(dayTypeList[2]);
    $('#dayType4').val(dayTypeList[3]);
    $('#dayType5').val(dayTypeList[4]);
    $('#dayType6').val(dayTypeList[5]);
    $('#dayType7').val(dayTypeList[6]);
}

But now I have timesheets of a month and not all months are the same. Is there a clean way to iterate over these id's? In the dayTypeList are the values for the inputs.

enter image description here

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

0

This works great, thanks.

$( "td .dayType" ).each(function( index ) {
   $(this).val(dayTypeList[index])
});
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