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

149
Vistas
How can I replace a CLICK in a <select> dropdown list with a CTRL+CLICK in Javascript?

A client wants a multi-select dropdown list that replaces the normal mouse click behavior with a CTRL+CLICK, as though the CTRL key is pressed while clicking the mouse. The client was warned that this changes expected behavior and wants it anyway. Initially I want to replace the default click behavior with the CTRL+CLICK behavior. I want to use the select element and not something else as some posts suggest.

My idea was to stop the click and replace it with a simulated CTRL+CLICK. I added the onmousedown attribute to the select statement. The JS disables the default click behavior and then I've tried to create and dispatch the same mouse click event with ctrlKey set to true...but nothing happens. Nothing is selected or deselected like the default CTRL+CLICK behavior should.

I'm new to JavaScript event handling, so I'm sure I'm missing something. Can someone help?

<select id="selectbox" multiple onmousedown="SelectDeselect(event)">
  <option id="option1">A</option>
  <option id="option2">B</option>
  <option id="option3">C</option>
</select>

<script>
function SelectDeselect(event) {
    event.preventDefault();
    optn = event.target;
    var ctrlClickEvent  = new MouseEvent("click", {
        ctrlKey: true,
    })
    document.getElementById(optn.id).dispatchEvent(ctrlClickEvent);
}
</script>
about 4 years ago · Juan Pablo Isaza
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