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

119
Views
event listener when selecting an option from select tag dynamically

I'm selecting an option from select tag in javascript by:

let btnH = document.querySelector('#btn_heads')
btnH.querySelector('[value="{{ $btn_heads }}"]').selected = true;

and the select tag has change listener:

btnH.addEventListener('change', s);

but it isn't wokring.

you can edit this snippet (I want an alert saying "selected : 7" without selecting it manually):

let i = document.querySelector('#i');

i.querySelector('[value="7"]').selected = true;

i.addEventListener('change', e=>{
  alert('selected : '+e.target.value);
});
<select id="i">
  <option value="1">1</option>
  <option value="2">2</option>
  <option value="3">3</option>
  <option value="4">4</option>
  <option value="5">5</option>
  <option value="6">6</option>
  <option value="7">7</option>
  <option value="8">8</option>
  <option value="9">9</option>
</select>

about 4 years ago · Santiago Gelvez
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!