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

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

0

This works great, thanks.

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