Reply
generating random numbers
Old 08-01-2006, 07:54 AM generating random numbers
Arfan's Avatar
Ultra Talker

Posts: 280
Hi,

on my website i need to make a button wen pressed it generates a random number between 1-3000 and puts it into a text box does anybody know how i can go about this

Thanks
__________________
OfficeBreak - Your home for Flash Games

For all your Flash work email me on
Arfan_zbst@yahoo.com
Arfan is offline
Reply With Quote
View Public Profile
 
When You Register, These Ads Go Away!
     
Old 08-01-2006, 11:42 AM Re: generating random numbers
funkdaddu's Avatar
Web Design Snob

Posts: 636
Code:
rNum = Math.ceil(Math.random() * 3000);
document.FormName.inputBox.value = rNum;

Last edited by funkdaddu : 08-01-2006 at 11:51 AM.
funkdaddu is offline
Reply With Quote
View Public Profile Visit funkdaddu's homepage!
 
Old 08-01-2006, 01:10 PM Re: generating random numbers
Arfan's Avatar
Ultra Talker

Posts: 280
hi i tried the following code from your script and it didnt work

<script type="text/javascript">

rNum = Math.ceil(Math.random() * 3000);
document.form1.inputBox.value = rNum;

</script>

<form name="form1">
<input name="randNum" type="text">
<input type="button" value="Generate"
onclick="rNum">

</form>


please help thanks
__________________
OfficeBreak - Your home for Flash Games

For all your Flash work email me on
Arfan_zbst@yahoo.com
Arfan is offline
Reply With Quote
View Public Profile
 
Old 08-01-2006, 01:40 PM Re: generating random numbers
funkdaddu's Avatar
Web Design Snob

Posts: 636
Well, I just gave you the basics, you didn't say how well you knew JS. So I'll assume you are a beginner - here is a full working version:
HTML Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

<html>

	<head>
		<meta http-equiv="content-type" content="text/html;charset=iso-8859-1">
		<title>Untitled Page</title>
		<script type="text/javascript"><!--
function generateRandom() {
	rNum = Math.ceil(Math.random() * 3000);
	document.form1.randNum.value = rNum;
}
//-->
</script>
	</head>

	<body bgcolor="#ffffff">
	<form name="form1">
		<input name="randNum" type="text">
		<input type="button" value="Generate" onclick="generateRandom();">
	</form>
</body>

</html>

Last edited by funkdaddu : 08-01-2006 at 01:42 PM.
funkdaddu is offline
Reply With Quote
View Public Profile Visit funkdaddu's homepage!
 
Old 08-01-2006, 02:11 PM Re: generating random numbers
Arfan's Avatar
Ultra Talker

Posts: 280
Thanks man really apreciated
__________________
OfficeBreak - Your home for Flash Games

For all your Flash work email me on
Arfan_zbst@yahoo.com
Arfan is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to generating random numbers
 

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off




   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML

 


Page generated in 0.13124 seconds with 13 queries