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

198
Visualizações
The value of input is not being assigned to a div

I want to get the text from the text area (id= getText), and than assign its value to the new div that I have created but the value is not being saved inside that new div.. I have tried many times but the value of the input is not saved and there is not change in when I click the button

let getText = document.getElementById("getText"); // this is     textarea
let select = document.getElementById("selectBtn"); //this is button
//this is another div
let result = document.getElementById("result");
let new_p = document.createElement("div"); //creating element
new_p.innerHTML = "";
result.appendChild(new_p); // adding into resut div  
//getting inner text of the input
let value = new_p.innerText;
//adding an event listener
select.addEventListener("click", function(e) {
    e.preventDefault();
    new_p.innerHTML = value;
    //it does not works and the value is not saved      
})
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

let getText = document.getElementById("getText"); // this is textarea
let select = document.getElementById("selectBtn"); //this is button

//this is another div
let result = document.getElementById("result");
let new_p = document.createElement("div"); //creating element
new_p.innerHTML = getText.value;
result.appendChild(new_p); // adding into resut div  
//getting inner text of the input
let value = new_p.innerText;


//adding an event listener
select.addEventListener("click", function(e) {
 e.preventDefault();
 new_p.innerHTML = getText.value;
 console.log(value)
 //it does not works and the value is not saved      
})

Replace new_p.innerHTML = ""; for new_p.innerHTML = getText.value

and inside of click event,

new_p.innerHTML = getText.value;

Moving forward, try to use online code editors, to post your code, Since it might be easier for anyone to assist you, Be aware to remove any personal info from the code.

Here is a fiddle with your code https://jsfiddle.net/k8b24n3q/12/

The reason was not working, was because you were setting on click event an undefined value.

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