Skip to main content
Participating Frequently
February 25, 2020
Question

Button that enters random number (between 1 and 21) in 100 diff fields

  • February 25, 2020
  • 1 reply
  • 498 views

I can't work this one out.

See image... I have 100 fields that i need a script on a button to enter a random number from 1 to 20 in them. The red button already clears them.

Any advice?

 

 

 

This topic has been closed for replies.

1 reply

try67
Community Expert
February 25, 2020

What are those fields called?

SavournAuthor
Participating Frequently
February 25, 2020

currently Tex01 to Tex100, but can be whatever is easiest

try67
Community Expert
February 25, 2020

You can use this code:

 

for (var i=1; i<=100; i++) {
var n = Math.floor(Math.random()*21)+1;
if (n==22) n--;
if (i<10) this.getField("Tex0"+i).value = n;
else this.getField("Tex"+i).value = n;
}