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

140
Views
How to trigger an event on a <select> element when the same value is selected?

The event type change will be triggered when a different item is selected from the combo box, but won't be triggered when the same item is selected again. What other event type or trick/loophole will get me the desired action?

const options = document.querySelector('#select');
options.addEventListener('change', function() { // won't be triggered when chosen the item chosen is the same
  console.log(this.value);
});
<select id="select">
  <option value="1" selected>1</option>
  <option value="2">2</option>
  <option value="3">3</option>
</select>

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Default and expected behaviour of a select, is the change event triggering when you CHANGE the select. If you just look at the options and choose the same option that was already selected, then no event is expected. So if you need to trigger each time, then you need to use the use click

In any case add a "Please select" to allow the event to trigger on the first actual options

document.querySelector('#select').addEventListener('click', function() { 
  if (this.value) console.log(this.value); 
});
<select id="select">
  <option value="" selected>Please select</option>
  <option value="1">1</option>
  <option value="2">2</option>
  <option value="3">3</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!