[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

onload make random number for each text field

Posted on 2010-11-18
4
Medium Priority
?
537 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 82

Accepted Solution

by:
leakim971 earned 200 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

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

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

This article explains how to prepare an HTML email signature template file containing dynamic placeholders for users' Azure AD data. Furthermore, it explains how to use this file to remotely set up a department-wide email signature policy in Office …
Without even knowing it, most of us are using web applications on a daily basis.  In fact, Gmail and Yahoo email, Twitter, Facebook, and eBay are used by most of us daily—and they are web applications. We generally confuse these web applications to…
In this tutorial viewers will learn how add a scalable full-width header using CSS3. Create a new HTML document with an internal stylesheet. Set a tiled background.:  Create a new div and name it Header. Position it with position:absolute at the top…
In this tutorial viewers will learn how to embed an audio file in a webpage using HTML5. Ensure your DOCTYPE declaration is set to HTML5: : The declaration should display (CODE) HTML5 is supported by the most recent versions of all major browsers…
Suggested Courses

650 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