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

172
Vistas
Avoid deleting entire input value on backspace

I have an input field which is deleting all the words its contains when I'm pressing backspace key.

I tried to implement a small code to delete the words letter by letter but I'm getting an error: selectInput.substring is not a function.

let selectInput = document.querySelector('#searchedWord');

selectInput.addEventListener("keydown", function(e) {
const key = e.key;
 if (key === "Backspace") {
   selectInput.value = selectInput.substring(0, selectInput.length -1);
   // other code to be exectuded below
 }
});

What am I missing?

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

"selectInput" is NOT a string in your context its a DOM-object (or DOM-tree [=array] if multiple elements have been found but since you used an ID "#"searchedWord we should be fine here)

you must access ".value" attribute

Try:

selectInput.value = selectInput.value.substring(0, selectInput.length -1)

You basically already did it right where you assigned it into. :D

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