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

137
Views
display current alert when change select value

I have a select (dropdown) and an input. When I enter a number at input, select value change with that number:

<input id="input" type="text" name="selectChanger">

<select id="select">
  <option value="" selected></option>
  <option value="0">floor 0</option>
  <option value="1">floor 1</option>
  <option value="2">floor 2</option>
</select>

I want when change select value, display an alert:

document.getElementById('input').addEventListener('input', function (event){
    let de = new Event('change');
    document.getElementById('select').dispatchEvent(de);
    document.getElementById('select').value = document.getElementById('input').value;
})

document.getElementById('select').addEventListener('change', function (event){
    alert(document.getElementById('select').text + ' was selected.')
})

Now when input number 0 , display was selected, and then input number 1 display floor 0 was selected but must display floor 1 was selected.

How can I fix this problem?

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

0

I think this will help you.

document.addEventListener('DOMContentLoaded', event => {
  const target_input  = document.querySelector('#input'),
        target_select = document.querySelector('#select');

  if (target_input != null) {
    target_input.addEventListener('input', event => {
        const { target } = event;

        for (const node of [...target_select.childNodes]) {
            if (node.nodeType == 1) {
                if (node.value == target.value) {
                node.selected = true;
                alert(`${node.textContent} is selected`)
                break;
              }
            }
        
        }
    })
  }
});
<input id="input" type="text" name="selectChanger">
<select id="select">
    <option value="" selected></option>
    <option value="0">floor 0</option>
    <option value="1">floor 1</option>
    <option value="2">floor 2</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!