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

125
Visualizações
HTML how to enter Tab and LF chars into an input box

I need to let the user input tabs into a text input box without it cycling focus to other elements and also let them enter multi-line strings (LF chars).

Any ideas? I'm trying to make a Whitespace (lang) IDE and so only being able to input one of the three chars needed makes it a bit difficult-

<input type="text" id="main_input">
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

Do you need an <input> element? It's by design intended to display a single line of text. For multi-line text, you can use the <textarea> element.

For example:

document.getElementById('mytext').addEventListener('keydown', function(e) {
  if (e.key == 'Tab') {
    e.preventDefault();
    var start = this.selectionStart;
    var end = this.selectionEnd;

    // set textarea value to: text before caret + tab + text after caret
    this.value = this.value.substring(0, start) + "\t" + this.value.substring(end);

    // put caret at right position again
    this.selectionStart = start + 1;
    this.selectionEnd = start + 1;
  }
});
<textarea id="mytext"></textarea>

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