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

220
Views
How can I disable the above options of a Select Time if I select a random time? JavaScript, JQuery

I'm tryign to made two selects with some time options and I can't figure it out how to resolve this. For example.

    If I chose 08:30:00 in the first select, I shouldn't chose 08:00:00 08:10:00 08:20:00 on the secondone.   

<select>
   <option selected disabled value="0">--Choose Start Time--</option>
   <option value="08:00:00">08:00:00</option>
   <option value="08:10:00">08:10:00</option>
   <option value="08:20:00">08:20:00</option>
   <option value="08:30:00">08:30:00</option>
   <option value="08:40:00">08:40:00</option>
   <option value="08:50:00">08:50:00</option>
 </select> 



<select>
   <option selected disabled value="0">--Choose End Time--</option>
   <option value="08:00:00">08:00:00</option>
   <option value="08:10:00">08:10:00</option>
   <option value="08:20:00">08:20:00</option>
   <option value="08:30:00">08:30:00</option>
   <option value="08:40:00">08:40:00</option>
   <option value="08:50:00">08:50:00</option>
 </select>

For example.

If I chose 08:30:00 in the first select, I shouldn't chose 08:00:00 08:10:00 08:20:00 on the 
secondone
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

You can use an event listener on the start time. Then loop through the end times to reset their disable setting to not disabled then compare the values.

let startTime = document.querySelector(".start-time");
let endTime = document.querySelectorAll(".end-time option");

startTime.addEventListener("change", function() {
  _val = this.value;
  let _disabled = document.querySelectorAll(".end-time option:disabled");
  
  if(_disabled){
  _disabled.forEach(function(end) {end.disabled = false;});//set all previously disabled options to be enabled
  }
  
  endTime.forEach(function(end) {
     if(end.value < _val && end.value != ""){
        end.disabled = true;
     }
  });
});
<select class="start-time">
  <option selected disabled value="0">--Choose Start Time--</option>
  <option value="08:00:00">08:00:00</option>
  <option value="08:10:00">08:10:00</option>
  <option value="08:20:00">08:20:00</option>
  <option value="08:30:00">08:30:00</option>
  <option value="08:40:00">08:40:00</option>
  <option value="08:50:00">08:50:00</option>
</select>



<select class="end-time">
  <option selected disabled value="0">--Choose End Time--</option>
  <option value="08:00:00">08:00:00</option>
  <option value="08:10:00">08:10:00</option>
  <option value="08:20:00">08:20:00</option>
  <option value="08:30:00">08:30:00</option>
  <option value="08:40:00">08:40:00</option>
  <option value="08:50:00">08:50:00</option>
</select>

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!