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

137
Vistas
Is there a way to print content of a array into a textarea?

I got a script that picks a random word from an array. What I want this to do is to print one of these arrays into a textarea after the user clicks a button.

<!DOCTYPE html>
<html>
    <head>

    </head>
    <body>
        <script>

        var myArray = [
            "Test",
            "Work",
            "Life"
            ];

            var randomItem = myArray[Math.floor(Math.random()*myArray.length)];
            document.body.innerHTML = randomItem;
        
        </script>
    </body>
 
</html>
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

You could select your text area with some javascript methods such as document.getElementById, document.querySelector and set its value.

const myArray = ["Test", "Work", "Life"];
// const textArea = document.getElementById('my-textarea');
const textArea = document.querySelector('#my-textarea');
function updateTextArea() {
  var randomItem = myArray[Math.floor(Math.random() * myArray.length)];
  textArea.value = randomItem;
}
<textarea name="" id="my-textarea" cols="30" rows="10"></textarea>
</br>
<button onclick="updateTextArea()">Update Textarea</button>

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