ok serious hard coders..
i think this is easy for you..
is a random number generator script…
7 chars.. the question is how do i add a prefix..
like MG9837295 and to display it on
a text box!!???
greetings for all code helpers!!!!
RT
<SCRIPT LANGUAGE=”JavaScript”>
<!– Begin
num= new Array(7);
for (i=0; i<7; i++) {
num[i]=Math.floor(7*Math.random()+1);
if (num[1]==num[0]) {
while (num[1]==num[0]) {
num[1]=Math.floor(7
}
}
if (num[2]==num[1] || num[2]==num[0]) {
while (num[2]==num[1] || num[2]==num[0]) {
num[2]=Math.floor(7*Math.random()+1);
}
}
if (num[3]==num[2] || num[3]==num[1] || num[3]==num[0]) {
while (num[3]==num[2] || num[3]==num[1] || num[3]==num[0]) {
num[3]=Math.floor(7
}
}
document.write(num[i]);
}
// End –>
</SCRIPT>
[CODE]<SCRIPT LANGUAGE="JavaScript">
<!-- Begin
function coder()
{
num=new Array(7);
document.getElementById('output').value = "";
for (i=0; i<7; i++)
{
num[i]=Math.floor(7*Math.random()+1);
if (num[1]==num[0])
{
while (num[1]==num[0])
{
num[1]=Math.floor(7*Math.random()+1);
}
}
if (num[2]==num[1] || num[2]==num[0])
{
while (num[2]==num[1] || num[2]==num[0])
{
num[2]=Math.floor(7*Math.random()+1);
}
}
if (num[3]==num[2] || num[3]==num[1] || num[3]==num[0])
{
while (num[3]==num[2] || num[3]==num[1] || num[3]==num[0])
{
num[3]=Math.floor(7*Math.random()+1);
}
}
document.getElementById('output').value+=(num[i]);
}
}
// End -->
</SCRIPT>
<input type="text" id="output" />
<input type="button" value="Run!" onclick="coder();"/>[/CODE]
[code=php]
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Random Number</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<script type="text/javascript">
<!-- Begin
function coder(num){
var R = Math.floor(parseInt(num)*Math.random()+1);
document.write('Random number: MG'+R);
}
// End -->
//-->
</script>
</head>
<body onLoad="coder(1000000)">
</body>
</html>
[/code]
[CODE]
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Random Number</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<script type="text/javascript">
<!-- Begin
function coder(num){
var R = Math.floor(parseInt(num)*Math.random()+1);
document.getElementById('[b]output[/b]').value = ("[b]prefix[/b]"+R);
}
// End -->
//-->
</script>
</head>
<body onLoad="coder(1000000)">
<form>
<input type="text" id="[b]output[/b]" />
</form>
</body>
</html> [/CODE]
[CODE]<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Random Number</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<script type="text/javascript">
<!-- Begin
function coder(){
num=new Array(7);
document.getElementById('[b]output[/b]').value = "[b]prefix[/b]";
for (i=0; i<7; i++)
{
num[i]=Math.floor(9*Math.random()+1);
document.getElementById('[b]output[/b]').value += (num[i]);
}
}
// End -->
//-->
</script>
</head>
<body onLoad="coder()">
<form>
<input type="text" id="[b]output[/b]" />
</form>
</body>
</html>[/CODE]
Then I would mash together both my post and swachtma's
This will generate 7 numbers from 0-9 and add a prefix.
[CODE]
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Random Number</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<script type="text/javascript">
<!-- Begin
[B]window.onload = coder(1000);[/B]
function coder(num){
var R = Math.floor(parseInt(num)*Math.random()+1);
document.getElementById('[b]output[/b]').value = ("[b]prefix[/b]"+R);
}
// End -->
//-->
</script>
</head>
<body>
<form>
<input type="text" id="[b]output[/b]" />
</form>
</body>
</html> [/CODE]
Just replace the bold prefix and make sure the element id's match. ?[/QUOTE]
[CODE]<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Random Number</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<script type="text/javascript">
<!-- Begin
function addLoadEvent(func) {
var oldonload = window.onload;
if (typeof window.onload != 'function') {
window.onload = func;
}
else {
window.onload = function() {
oldonload();
func();
}
}
}
function coder(){
num=new Array(7);
document.getElementById('output').value = "prefix";
for (i=0; i<7; i++)
{
num[i]=Math.floor(9*Math.random()+1);
document.getElementById('output').value += (num[i]);
}
}
addLoadEvent(function () { coder(); });
// End -->
//-->
</script>
</head>
<body onLoad="coder()">
<form>
<input type="text" id="output" />
</form>
</body>
</html>[/CODE]
[CODE]<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Random Number</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<script type="text/javascript">
<!-- Begin
function addLoadEvent(func) {
var oldonload = window.onload; // Select onload event
if (typeof window.onload != 'function') { // If the onload isn't holding a function
window.onload = func; // Stick the function in
}
else {
window.onload = function() { // Otherwise do all the old+the new
oldonload();
func();
}
}
}
function coder(){
num=new Array(7); // Seven element array (thats the size requested)
document.getElementById('output').value = "prefix";
for (i=0; i<7; i++) // Loop
{
num[i]=Math.floor(9*Math.random()+1);
document.getElementById('output').value += (num[i]); // Append
}
}
addLoadEvent(function () { coder(); }); // Add coder event to onload using addLoadEvent
// End -->
//-->
</script>
</head>
<body onLoad="coder()">
<form>
<input type="text" id="output" />
</form>
</body>
</html>[/CODE]
Hope that explained it a bit.[CODE] num[i]=Math.floor(9*Math.random()+1);[/CODE]
[CODE] num[i]=Math.floor(10*Math.random());[/CODE]
0.1.9 — BETA 6.16