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

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

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 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