onload make random number for each text field

Can someone tell me why this does not work, looks like it would to me!

<script type="text/javascript">
function rnd(max) {
  var rndnum = max * Math.random();
  rndnum = Math.ceil(rndnum);
  return rndnum;
function start() {
var a = rnd;
var els = document.getElementsByClassName('Numbers');
for (i=0; i < els.length; i++){
  a = document.f1.t[i].value;
<body onload="start();">
<form action="#" name=f1 >
<input type="text" name="t1" class="Numbers" value=""><br>
<input type="text" name="t2" class="Numbers" value=""><br>
<input type="text" name="t3" class="Numbers" value=""><br>

Open in new window

Who is Participating?
leakim971Connect With a Mentor PluritechnicianCommented:
Please note getElementsByClassName is not available on MS Internet Explorer

Else :

replace :
a = document.f1.t[i].value;

by :
els[i].value = a(10);

Open in new window


... Unfortunately there is no such method as document.getElementsByClassName so we can't grab a collection of all of the tags that share a class that way, we'll have to find another way to do it.

Read that page for defining a getElementsByClassName function .
johnh619Author Commented:
HonorGod; I looked at the article but it must be wrong since I am using this method and after making the change that leakim971 suggested my code is now working perfectly.
johnh619Author Commented:
I received the requested help promptly and the new code works perfectly.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.