Solved

onload make random number for each text field

Posted on 2010-11-18
4
529 Views
Last Modified: 2012-05-10
Can someone tell me why this does not work, looks like it would to me!


<html>

<head>

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

  }} 

</script>

</head>

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

</form>

</body>

</html>

Open in new window

0
Comment
Question by:johnh619
  • 2
4 Comments
 
LVL 82

Accepted Solution

by:
leakim971 earned 50 total points
ID: 34169378
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

0
 
LVL 41

Expert Comment

by:HonorGod
ID: 34169395
http://javascript.about.com/library/bldom08.htm

... 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 .
0
 

Author Comment

by:johnh619
ID: 34169643
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.
0
 

Author Closing Comment

by:johnh619
ID: 34169654
I received the requested help promptly and the new code works perfectly.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
JavaScript waiting 14 66
Javascript create file issue 4 45
Regular Expression 1-100 with two digits 15 21
Split in Javascript 5 30
Not sure what the best email signature size is? Are you worried about email signature image size? Follow this best practice guide.
Finding original email is quite difficult due to their duplicates. From this article, you will come to know why multiple duplicates of same emails appear and how to delete duplicate emails from Outlook securely and instantly while vital emails remai…
The viewer will receive an overview of the basics of CSS showing inline styles. In the head tags set up your style tags: (CODE) Reference the nav tag and set your properties.: (CODE) Set the reference for the UL element and styles for it to ensu…
The viewer will the learn the benefit of plain text editors and code an HTML5 based template for use in further tutorials.

929 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now