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

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