Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

130
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda