Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

289
Views
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 answers
Answer question

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 Report

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!