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

156
Vistas
How to save contenteditable input to a variable so I can print it on screen

I have this code and I want to save a contenteditable text to a variable so i can print it on screen. HTML:

    <input type="button" value="save edits" onclick="saveEdits()"/>
    <p id="update"></p>```

and JS:

```function saveEdits() {
    //get the editable element
    var editElem = document.getElementById("myText").value;
    document.getElementById("update").innerHTML=editElem;
    //write a confirmation to the user
  }```

Thank you for your time.
about 4 years ago · Juan Pablo Isaza
3 Respuestas
Responde la pregunta

0

I'd try using innerHTML:

function saveEdits() {
    //get the editable element
    document.getElementById("update").innerHTML = document.getElementById("myText").innerHTML;
    //write a confirmation to the user
}
about 4 years ago · Juan Pablo Isaza Denunciar

0

From what I understand you want this :

function saveEdits() {
    //get the editable element
    var editElem = document.getElementById("myText").value;
    document.getElementById("update").innerHTML=editElem;
    //write a confirmation to the user
    alert("your text have been saved");
  }
<input type="text" placeholder="type content here" id="myText">
<input type="button" value="save edits" onclick="saveEdits()"/>
    <p id="update"></p>

The text is stocked in the editElem variable.

about 4 years ago · Juan Pablo Isaza Denunciar

0

Just change .value to .innerHTML .

function saveEdits() {
//get the editable element
var editElem = document.getElementById("myText").innerHTML;
document.getElementById("update").innerHTML=editElem;
//write a confirmation to the user
  }
<h1 id="myText" contenteditable="true">Title</h1>
    <input type="button" value="save edits" onclick="saveEdits()"/>
    <p id="update"></p>

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