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

290
Visualizações
print input value on the next line and so on

Question:- i have write a code but it print values only once and i want to print value line by line nextupon the old value like a post ok?

var post = []

function getVal() {
  // creating varable val for select all input data.
  const val = document.querySelector('input').value;
  document.getElementById('input').value = "";
  console.log(val);

  //store data in an array for print.
  post.push(val)
  //call for print the input value in span tag
  document.getElementById('print1').innerHTML = val
  console.log(post);
}
<input id="input" class="inp" type="text" name="textbox">
<button id="btn" class="postbutton" type="button" name="button" onclick="getVal()">Post</button>
<span id="print1"></span>

about 4 years ago · Juan Pablo Isaza
2 Respostas
Responde à pergunta

0

Replace the following line of function getVal()

document.getElementById('print1').innerHTML = val

With

document.getElementById('print1').innerHTML += val + "<br>"

var post = []
function getVal() {

    // creating varable val for select all input data.
    const val = document.querySelector('input').value;
    document.getElementById('input').value = "";
    console.log(val);
    
    //store data in an array for print.
    post.push(val)
    //call for print the input value in span tag
    document.getElementById('print1').innerHTML += val + "<br>"
    console.log(post);
}
 <input id="input" class="inp" type="text" name="textbox">
                    <button id="btn" class="postbutton" type="button" name="button" onclick="getVal()">Post</button>
                    <span id="print1"></span>

about 4 years ago · Juan Pablo Isaza Relatório

0

You can try using join , just adjust one line of code

replace

document.getElementById('print1').innerHTML = val

with

document.getElementById('print1').innerHTML = post.join('<br/>');

var post = []

function getVal() {
  // creating varable val for select all input data.
  const val = document.querySelector('input').value;
  document.getElementById('input').value = "";

  //store data in an array for print.
  post.push(val)
  //call for print the input value in span tag
  document.getElementById('print1').innerHTML = post.join('<br/>');
}
<input id="input" class="inp" type="text" name="textbox">
<button id="btn" class="postbutton" type="button" name="button" onclick="getVal()">Post</button>
<br/>
<span id="print1"></span>

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