Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

JavaScript Forum


You are currently viewing our JavaScript Forum as a guest. Please register to participate.
Login



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

Posts: 280
Trades: 0
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
__________________

Please login or register to view this content. Registration is FREE


For all your Flash work email me on

Please login or register to view this content. Registration is FREE
Arfan is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 08-01-2006, 12:42 PM Re: generating random numbers
funkdaddu's Avatar
Web Design Snob

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

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

Posts: 280
Trades: 0
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
__________________

Please login or register to view this content. Registration is FREE


For all your Flash work email me on

Please login or register to view this content. Registration is FREE
Arfan is offline
Reply With Quote
View Public Profile
 
Old 08-01-2006, 02:40 PM Re: generating random numbers
funkdaddu's Avatar
Web Design Snob

Posts: 635
Trades: 0
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 02:42 PM..
funkdaddu is offline
Reply With Quote
View Public Profile Visit funkdaddu's homepage!
 
Old 08-01-2006, 03:11 PM Re: generating random numbers
Arfan's Avatar
Ultra Talker

Posts: 280
Trades: 0
Thanks man really apreciated
__________________

Please login or register to view this content. Registration is FREE


For all your Flash work email me on

Please login or register to view this content. Registration is FREE
Arfan is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to generating random numbers
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

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

BB 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.18066 seconds with 12 queries