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

109
Views
An addEventListener with keydown results in an empty string upon the first key in a textarea

I have a textarea tag that takes in values to use for something else. When I press on a key, the value of it is an empty string. However, the keys pressed after the first key show up just fine. For instance, if I type, "hello" the value would be, "ello". I want it so the value of the first key would show up.

Here's my code,

const editor = document.getElementById(‘editor’);
editor.addEventListener('keydown', (event => {
    let value = editor.value;
    console.log(value);
}));

This is my HTML for the textarea, in case if needed,

<textarea autofocus id="editor"></textarea>

Thanks.

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

To see all the characters as you type use the keyup rather than keydown as the event type.

editor.addEventListener('keyup',function(e) {
    let value = this.value;
    let preview=document.getElementById('preview');
    console.log(value);
    preview.innerHTML=value;
});
<textarea autofocus id="editor"></textarea>
<div id='preview'></div>

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!