-3

I've been trying to randomly select an item from an array and displaying the chosen array in a form field. I've found how to display the item in a paragraph by using <p id="item"> </p> (might be incorrect) but can't figure out how to display it in a form field :/ Help, please.

charlietfl
  • 170,828
  • 13
  • 121
  • 150
user3650090
  • 9
  • 1
  • 1
  • 3

1 Answers1

0

You can get a random value like this

var rand = myArray[Math.floor(Math.random() * myArray.length)];

Then you can display it in the form field by using

document.getElementById('id1').value = rand

where id1 is the id of your formfield

Ad Fundum
  • 665
  • 6
  • 22