Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

187
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda