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

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

0

This works great, thanks.

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