Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

173
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda