Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

115
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!