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

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

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 Denunciar

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