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

189
Views
HTML Textarea does not keep its content (Javascript)

A html text area is binded to a popup screen.

textarea

Texts dont remain in the area after the popup is re-opened. Save button saves the content of textarea to a variable:

let textAreaContent=""; //in the beginning of script page.

function handleClick(){
    textAreaContent = document.getElementById("textarea").value;
    console.log(textAreaContent)
    return null;
}

I can see the changed value of textarea content in console when i click on save button. I tried to assing textAreaContent variable to HTML textarea but it didnt work. Popup page:

<textarea id="textarea" rows="4" cols="40" style="border 1px solid black">${textAreaContent}</textarea>
<button onClick={handleClick()}>Save</button>

Why the content of textarea does not change? What am i doing wrong?

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

0

First you made a typo in with the style attribute, Here is the correct syntax.

style="border: 1px solid black;"

For the onClick handler try the following instead :

<button onClick="handleClick()">Save</button>

If you want the information to persist you can use a global variable or session storage.

  function handleClick() {
    var textAreaContent = document.getElementById("textarea").value;
    sessionStorage.setItem("textAreaContent", textAreaContent);
    return null;
  }

You can then get the information later with the sessionStorage.getItem method later and add the value back

// whenever popup opens, 
document.getElementById("textarea").value = sessionStorage.getItem('textAreaContent')
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!