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

107
Views
for loop with array of strings rendering the same thing twice?

I am building in javascript a simple feedback that has a text area and is grabbing the text and displaying a successful message when the add button is clicked. When the view feedback button is clicked it should render the feedback and it does but if I click the button once and then type in the text area again and again it keeps rendering multiple times the same feedback message. Attached is my javascript code.

var array = Array();
var x = 0;
function addFeedback() {
    array[x] = document.getElementById('feedback').value;
    x++;

    document.getElementById('feedback').value = '';

    document.getElementById('result').innerHTML =
        '<h2><h3> Your have successfully Added Feedback!</h3></h2>';
}

var feedback = '';

function displayFeedback() {
    for (var i = 1; i < array.length + 1; i++) {
        feedback = array[i - 1] + '<br/>';
        console.log(feedback);
    }
    document.getElementById('result').innerHTML =
        '<h2>feedback Details: </h2>' + feedback.split('<br>');
}
<html>
    <head>
    <script src="script.js" type="text/javascript"> </script>
  </head>
  <body> 
    <!-- Fill code here -->
     <div>
         <h2>Feedback for the ART OF LIVING</h2>
         <div>
             <label for="feedback"></label>Enter the Feedback:
                <textarea id="feedback" name="feedback" value="feedback" type="text"></textarea>
            <div>
                <input type="button" id="create" name="create" onclick="javascript:addFeedback()">Add Feedback</input><br/>
                <input type="button" id="view" name="view" onclick="javascript:displayFeedback()">View feedback</input>
            </div>
            <div id="result"></div>
         </div>
     </div>
    </body>
</html>

about 4 years ago · Juan Pablo Isaza
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!