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

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

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