/    Sign up×
Community /Pin to ProfileBookmark

Getting a random number into a text field?

I just can’t figure out how to get a random number into a text field.

I want to have a random drawing where people can enter their own “lottery number” and they can get a “Quick Pick”. I want to make a certain set of numbers appear in a text box. I tried making an alert do that, but I tried everything and couldn’t do it and I’m moving onto getting it into a text box.

I’d really appreciate any help.

[B]THANKS[/B]

to post a comment
JavaScript

6 Comments(s)

Copy linkTweet thisAlerts:
@bathurst_guyFeb 17.2007 — What do you have so far?
Copy linkTweet thisAlerts:
@imageniusauthorFeb 17.2007 — I only have the code for the alert, but here it is


[B]<HTML>

<HEAD>



<TITLE>Get a Code</TITLE>

<SCRIPT language="JavaScript">

<--!

function QP()

{

var QPnum=new Array(100)
QP[0]='9, 26, 18, 56, 23';
QP[1]='36, 41, 8, 16, 20';
QP[2]='21, 11, 62, 28, 56';
QP[3]='8, 53, 36, 55, 56';
QP[4]='37, 21, 33, 16, 64';
QP[01]='52, 12, 37, 41, 39';
QP[11]='13, 29, 60, 52, 19';
QP[21]='5, 69, 4, 42, 2';
QP[31]='41, 42, 57, 20, 21';
QP[41]='67, 28, 36, 61, 35';
QP[02]='8, 35, 26, 29, 23';
QP[12]='25, 15, 20, 8, 65';
QP[22]='9, 12, 10, 32, 28';
QP[32]='19, 30, 13, 11, 15';
QP[42]='22, 18, 57, 13, 46';
QP[03]='24, 52, 17, 10, 29';
QP[13]='31, 14, 10, 54, 7';
QP[23]='34, 30, 37, 63, 68';
QP[33]='15, 15, 63, 38, 53';
QP[43]='55, 24, 20, 40, 7';
QP[04]='26, 57, 35, 31, 46';
QP[14]='2, 33, 22, 32, 37';
QP[24]='41, 14, 38, 19, 33';
QP[34]='53, 53, 18, 49, 21';
QP[44]='50, 32, 54, 27, 61';
QP[05]='48, 39, 63, 29, 60';
QP[15]='11, 8, 33, 22, 51';
QP[25]='49, 23, 20, 45, 18';
QP[35]='61, 64, 45, 68, 12';
QP[45]='19, 63, 33, 2, 52';
QP[06]='9, 26, 16, 15, 1';
QP[16]='7, 28, 11, 62, 51';
QP[26]='26, 36, 24, 37, 26';
QP[36]='69, 7, 69, 52, 60';
QP[46]='13, 44, 65, 7, 4';
QP[07]='65, 29, 17, 58, 16';
QP[17]='29, 67, 29, 37, 36';
QP[27]='32, 38, 46, 6, 39';
QP[37]='56, 42, 20, 48, 24';
QP[47]='23, 19, 16, 24, 2';
QP[08]='15, 49, 60, 26, 9';
QP[18]='60, 66, 63, 38, 8';
QP[28]='20, 58, 59, 54, 3';
QP[38]='25, 63, 63, 44, 39';
QP[48]='47, 9, 24, 8, 19';
QP[09]='47, 58, 66, 43, 14';
QP[19]='64, 29, 69, 60, 12';
QP[29]='66, 59, 66, 34, 33';
QP[39]='36, 38, 24, 46, 19';
QP[49]='69, 24, 58, 19, 44';
QP[011]='63, 44, 4, 62, 46';
QP[111]='21, 27, 64, 40, 63';
QP[211]='60, 9, 13, 51, 65';
QP[311]='39, 23, 60, 59, 58';
QP[411]='6, 51, 55, 9, 54';
QP[022]='40, 25, 32, 2, 50';
QP[122]='41, 44, 34, 44, 1';
QP[222]='26, 64, 37, 10, 2';
QP[322]='33, 50, 9, 36, 10';
QP[422]='13, 24, 37, 67, 64';
QP[033]='35, 4, 68, 20, 58';
QP[133]='27, 65, 61, 34, 18';
QP[233]='21, 5, 38, 23, 60';
QP[333]='44, 16, 19, 56, 39';
QP[433]='26, 34, 36, 43, 20';
QP[044]='38, 4, 59, 57, 67';
QP[144]='38, 46, 39, 46, 13';
QP[244]='16, 49, 41, 8, 45';
QP[344]='7, 37, 64, 42, 53';
QP[444]='48, 14, 51, 33, 3';
QP[055]='22, 15, 59, 49, 58';
QP[155]='21, 6, 43, 35, 7';
QP[255]='30, 44, 64, 6, 63';
QP[355]='32, 16, 1, 38, 23';
QP[455]='68, 21, 36, 49, 32';
QP[066]='56, 64, 69, 33, 4';
QP[166]='14, 65, 8, 49, 35';
QP[266]='35, 45, 18, 36, 16';
QP[366]='17, 11, 63, 50, 62';
QP[466]='64, 35, 15, 56, 63';
QP[077]='30, 34, 28, 38, 20';
QP[177]='37, 20, 42, 55, 59';
QP[277]='19, 58, 26, 15, 12';
QP[377]='50, 24, 62, 13, 28';
QP[477]='1, 49, 12, 14, 4';
QP[088]='57, 15, 63, 45, 65';
QP[188]='49, 28, 67, 17, 52';
QP[288]='24, 10, 11, 11, 58';
QP[388]='11, 62, 56, 64, 19';
QP[488]='43, 30, 26, 28, 35';
QP[099]='26, 11, 61, 3, 22';
QP[199]='41, 63, 64, 32, 48';
QP[299]='51, 49, 38, 56, 9';
QP[399]='36, 56, 7, 13, 54';
QP[499]='66, 64, 22, 12, 6';
QP[000]='67, 40, 28, 38, 43';
QP[100]='4, 22, 50, 60, 46';
QP[200]='4, 22, 50, 60, 46';
QP[300]='30, 68, 67, 67, 58';
QP[400]='3, 61, 12, 24, 3';


alert(QP[WhichQP]);

}

//-->

</SCRIPT>



</HEAD>

<BODY>

<H2>This is a random 5 number pick (if you click the button) that may be picked more than once. Write it down and type it into the following textbox.</H2>

<br>

<H2>If you would like, you can make up your own 5 number pick in the form 1, 2, 3, 4, 5 (must be in that exact way). Just type it into the box.</H2>

<br>

<form action="#">

<div>

<input type="button" value="Get a QP!" onClick="QP

()"></input>

</div>

</form>




<FORM METHOD=POST ACTION="mailto:[email protected]" ENCTYPE="text/plain">

<p>E-mail<INPUT TYPE="text" NAME="E-mail" SIZE=18>

<p>Number<INPUT TYPE="text" NAME="Number" SIZE=18>

<BR>

<INPUT TYPE="submit" VALUE="Submit">

<INPUT TYPE="reset" VALUE="Clear">


</FORM>


</BODY>[/B]


I'm kind of new, but I know the basic stuff. I've gone to so many sites but none of their codes work.
Copy linkTweet thisAlerts:
@mrhooFeb 17.2007 — replace the alert with

var L= QP.length;

tem=L;

while(!QP[tem])tem=Math.round(Math.random*L);

document.getElementsByName('Number')[0].value=QP[tem];

If you want to return a 'more' random 5 digit string you could use something like this:
[CODE]function QP(num,limit){
num= num || 5;
limit= limit || 70;
var A=[];
var count= 0;
while(count++ < limit) A[count]= count;
var B= [], tem= limit, temp;
while(num--){
--tem;
temp= Math.round(Math.random()*tem)+1;
B.push(A.splice(temp,1));
}
B.sort(function(a,b){return a-b});
document.getElementsByName('Number')[0].value= B.join(' ');
}[/CODE]
Copy linkTweet thisAlerts:
@imageniusauthorFeb 17.2007 — So It should look like this?

<HTML>

<HEAD>

<TITLE>Get a Code</TITLE>

<SCRIPT language="JavaScript">

<--!

function QP()

{

var QPnum=new Array(100)
QP[0]='9, 26, 18, 56, 23';
QP[1]='36, 41, 8, 16, 20';
QP[2]='21, 11, 62, 28, 56';
QP[3]='8, 53, 36, 55, 56';
QP[4]='37, 21, 33, 16, 64';
QP[01]='52, 12, 37, 41, 39';
QP[11]='13, 29, 60, 52, 19';
QP[21]='5, 69, 4, 42, 2';
QP[31]='41, 42, 57, 20, 21';
QP[41]='67, 28, 36, 61, 35';
QP[02]='8, 35, 26, 29, 23';
QP[12]='25, 15, 20, 8, 65';
QP[22]='9, 12, 10, 32, 28';
QP[32]='19, 30, 13, 11, 15';
QP[42]='22, 18, 57, 13, 46';
QP[03]='24, 52, 17, 10, 29';
QP[13]='31, 14, 10, 54, 7';
QP[23]='34, 30, 37, 63, 68';
QP[33]='15, 15, 63, 38, 53';
QP[43]='55, 24, 20, 40, 7';
QP[04]='26, 57, 35, 31, 46';
QP[14]='2, 33, 22, 32, 37';
QP[24]='41, 14, 38, 19, 33';
QP[34]='53, 53, 18, 49, 21';
QP[44]='50, 32, 54, 27, 61';
QP[05]='48, 39, 63, 29, 60';
QP[15]='11, 8, 33, 22, 51';
QP[25]='49, 23, 20, 45, 18';
QP[35]='61, 64, 45, 68, 12';
QP[45]='19, 63, 33, 2, 52';
QP[06]='9, 26, 16, 15, 1';
QP[16]='7, 28, 11, 62, 51';
QP[26]='26, 36, 24, 37, 26';
QP[36]='69, 7, 69, 52, 60';
QP[46]='13, 44, 65, 7, 4';
QP[07]='65, 29, 17, 58, 16';
QP[17]='29, 67, 29, 37, 36';
QP[27]='32, 38, 46, 6, 39';
QP[37]='56, 42, 20, 48, 24';
QP[47]='23, 19, 16, 24, 2';
QP[08]='15, 49, 60, 26, 9';
QP[18]='60, 66, 63, 38, 8';
QP[28]='20, 58, 59, 54, 3';
QP[38]='25, 63, 63, 44, 39';
QP[48]='47, 9, 24, 8, 19';
QP[09]='47, 58, 66, 43, 14';
QP[19]='64, 29, 69, 60, 12';
QP[29]='66, 59, 66, 34, 33';
QP[39]='36, 38, 24, 46, 19';
QP[49]='69, 24, 58, 19, 44';
QP[011]='63, 44, 4, 62, 46';
QP[111]='21, 27, 64, 40, 63';
QP[211]='60, 9, 13, 51, 65';
QP[311]='39, 23, 60, 59, 58';
QP[411]='6, 51, 55, 9, 54';
QP[022]='40, 25, 32, 2, 50';
QP[122]='41, 44, 34, 44, 1';
QP[222]='26, 64, 37, 10, 2';
QP[322]='33, 50, 9, 36, 10';
QP[422]='13, 24, 37, 67, 64';
QP[033]='35, 4, 68, 20, 58';
QP[133]='27, 65, 61, 34, 18';
QP[233]='21, 5, 38, 23, 60';
QP[333]='44, 16, 19, 56, 39';
QP[433]='26, 34, 36, 43, 20';
QP[044]='38, 4, 59, 57, 67';
QP[144]='38, 46, 39, 46, 13';
QP[244]='16, 49, 41, 8, 45';
QP[344]='7, 37, 64, 42, 53';
QP[444]='48, 14, 51, 33, 3';
QP[055]='22, 15, 59, 49, 58';
QP[155]='21, 6, 43, 35, 7';
QP[255]='30, 44, 64, 6, 63';
QP[355]='32, 16, 1, 38, 23';
QP[455]='68, 21, 36, 49, 32';
QP[066]='56, 64, 69, 33, 4';
QP[166]='14, 65, 8, 49, 35';
QP[266]='35, 45, 18, 36, 16';
QP[366]='17, 11, 63, 50, 62';
QP[466]='64, 35, 15, 56, 63';
QP[077]='30, 34, 28, 38, 20';
QP[177]='37, 20, 42, 55, 59';
QP[277]='19, 58, 26, 15, 12';
QP[377]='50, 24, 62, 13, 28';
QP[477]='1, 49, 12, 14, 4';
QP[088]='57, 15, 63, 45, 65';
QP[188]='49, 28, 67, 17, 52';
QP[288]='24, 10, 11, 11, 58';
QP[388]='11, 62, 56, 64, 19';
QP[488]='43, 30, 26, 28, 35';
QP[099]='26, 11, 61, 3, 22';
QP[199]='41, 63, 64, 32, 48';
QP[299]='51, 49, 38, 56, 9';
QP[399]='36, 56, 7, 13, 54';
QP[499]='66, 64, 22, 12, 6';
QP[000]='67, 40, 28, 38, 43';
QP[100]='4, 22, 50, 60, 46';
QP[200]='4, 22, 50, 60, 46';
QP[300]='30, 68, 67, 67, 58';
QP[400]='3, 61, 12, 24, 3';

[B]*/This is what I changed, but I don't think it's right because it didn't work.[/B]

var L= QP.length;

tem=L;

while(!QP[tem])tem=Math.round(Math.random*
L);

document.getElementsByName('Number')[0].value=QP[tem];

}

//-->

</SCRIPT>



</HEAD>

<BODY>

<H2>This is a random 5 number pick (if you click the button) that may be picked more than once. Write it down and type it into the following textbox.</H2>

<br>

<H2>If you would like, you can make up your own 5 number pick in the form 1, 2, 3, 4, 5 (must be in that exact way). Just type it into the box.</H2>

<br>

<form action="#">

<div>

<input type="button" value="Get a QP!" onClick="QP

()"></input>

</div>

</form>




<FORM METHOD=POST ACTION="mailto:[email protected]" ENCTYPE="text/plain">

<p>E-mail<INPUT TYPE="text" NAME="E-mail" SIZE=18>

<p>Number<INPUT TYPE="text" NAME="Number" SIZE=18>

<BR>

<INPUT TYPE="submit" VALUE="Submit">

<INPUT TYPE="reset" VALUE="Clear">


</FORM>


</BODY>




because it didn't seem to work in firefox or IE
Copy linkTweet thisAlerts:
@mrhooFeb 17.2007 — You define QP as a function, QPnum as an array, but then add array elements to QP, the function.

Change someone's name.

You can't have array elements beginning with 0- (except 0)

Use type="text/javascript" in the script declaration.

Input does not have a closing tag(</input>)

This works:

<HTML>

<HEAD>

<TITLE>Get a Code</TITLE>

<SCRIPT type="text/javascript">

function QPnum()

{

var QP=new Array()

QP[0]='9, 26, 18, 56, 23';

QP[1]='36, 41, 8, 16, 20';

QP[2]='21, 11, 62, 28, 56';

QP[3]='8, 53, 36, 55, 56';

QP[4]='37, 21, 33, 16, 64';

//QP[01]='52, 12, 37, 41, 39';

QP[11]='13, 29, 60, 52, 19';

QP[21]='5, 69, 4, 42, 2';

QP[31]='41, 42, 57, 20, 21';

QP[41]='67, 28, 36, 61, 35';

//QP[02]='8, 35, 26, 29, 23';

QP[12]='25, 15, 20, 8, 65';

QP[22]='9, 12, 10, 32, 28';

QP[32]='19, 30, 13, 11, 15';

QP[42]='22, 18, 57, 13, 46';

//QP[03]='24, 52, 17, 10, 29';

QP[13]='31, 14, 10, 54, 7';

QP[23]='34, 30, 37, 63, 68';

QP[33]='15, 15, 63, 38, 53';

QP[43]='55, 24, 20, 40, 7';

//QP[04]='26, 57, 35, 31, 46';

QP[14]='2, 33, 22, 32, 37';

QP[24]='41, 14, 38, 19, 33';

QP[34]='53, 53, 18, 49, 21';

QP[44]='50, 32, 54, 27, 61';

//QP[05]='48, 39, 63, 29, 60';

QP[15]='11, 8, 33, 22, 51';

QP[25]='49, 23, 20, 45, 18';

QP[35]='61, 64, 45, 68, 12';

QP[45]='19, 63, 33, 2, 52';

//QP[06]='9, 26, 16, 15, 1';

QP[16]='7, 28, 11, 62, 51';

QP[26]='26, 36, 24, 37, 26';

QP[36]='69, 7, 69, 52, 60';

QP[46]='13, 44, 65, 7, 4';

//QP[07]='65, 29, 17, 58, 16';

QP[17]='29, 67, 29, 37, 36';

QP[27]='32, 38, 46, 6, 39';

QP[37]='56, 42, 20, 48, 24';

QP[47]='23, 19, 16, 24, 2';

//QP[08]='15, 49, 60, 26, 9';

QP[18]='60, 66, 63, 38, 8';

QP[28]='20, 58, 59, 54, 3';

QP[38]='25, 63, 63, 44, 39';

QP[48]='47, 9, 24, 8, 19';

//QP[09]='47, 58, 66, 43, 14';

QP[19]='64, 29, 69, 60, 12';

QP[29]='66, 59, 66, 34, 33';

QP[39]='36, 38, 24, 46, 19';

QP[49]='69, 24, 58, 19, 44';

//QP[011]='63, 44, 4, 62, 46';

QP[111]='21, 27, 64, 40, 63';

QP[211]='60, 9, 13, 51, 65';

QP[311]='39, 23, 60, 59, 58';

QP[411]='6, 51, 55, 9, 54';

//QP[022]='40, 25, 32, 2, 50';

QP[122]='41, 44, 34, 44, 1';

QP[222]='26, 64, 37, 10, 2';

QP[322]='33, 50, 9, 36, 10';

QP[422]='13, 24, 37, 67, 64';

//QP[033]='35, 4, 68, 20, 58';

QP[133]='27, 65, 61, 34, 18';

QP[233]='21, 5, 38, 23, 60';

QP[333]='44, 16, 19, 56, 39';

QP[433]='26, 34, 36, 43, 20';

//QP[044]='38, 4, 59, 57, 67';

QP[144]='38, 46, 39, 46, 13';

QP[244]='16, 49, 41, 8, 45';

QP[344]='7, 37, 64, 42, 53';

QP[444]='48, 14, 51, 33, 3';

//QP[055]='22, 15, 59, 49, 58';

QP[155]='21, 6, 43, 35, 7';

QP[255]='30, 44, 64, 6, 63';

QP[355]='32, 16, 1, 38, 23';

QP[455]='68, 21, 36, 49, 32';

//QP[066]='56, 64, 69, 33, 4';

QP[166]='14, 65, 8, 49, 35';

QP[266]='35, 45, 18, 36, 16';

QP[366]='17, 11, 63, 50, 62';

QP[466]='64, 35, 15, 56, 63';

//QP[077]='30, 34, 28, 38, 20';

QP[177]='37, 20, 42, 55, 59';

QP[277]='19, 58, 26, 15, 12';

QP[377]='50, 24, 62, 13, 28';

QP[477]='1, 49, 12, 14, 4';

//QP[088]='57, 15, 63, 45, 65';

QP[188]='49, 28, 67, 17, 52';

QP[288]='24, 10, 11, 11, 58';

QP[388]='11, 62, 56, 64, 19';

QP[488]='43, 30, 26, 28, 35';

//QP[099]='26, 11, 61, 3, 22';

QP[199]='41, 63, 64, 32, 48';

QP[299]='51, 49, 38, 56, 9';

QP[399]='36, 56, 7, 13, 54';

QP[499]='66, 64, 22, 12, 6';

//QP[000]='67, 40, 28, 38, 43';

QP[100]='4, 22, 50, 60, 46';

QP[200]='4, 22, 50, 60, 46';

QP[300]='30, 68, 67, 67, 58';

QP[400]='3, 61, 12, 24, 3';

var L= QP.length;

var A=[];

tem=L;

while(L--)if(QP[L])A.push(QP[L]);

L=A.length-1;

tem=Math.round(Math.random()*L);

document.getElementsByName('Number')[0].value=A[tem];

}

</SCRIPT>



</HEAD>

<BODY>

<H2>This is a random 5 number pick (if you click the button) that may be picked more than once. Write it down and type it into the following textbox.</H2>

<br>

<H2>If you would like, you can make up your own 5 number pick in the form 1, 2, 3, 4, 5 (must be in that exact way). Just type it into the box.</H2>

<br>

<form action="">

<div>

<input type="button" value="Get a QP!" onClick="QPnum()">

</div>

</form>




<FORM METHOD=POST ACTION="" ENCTYPE="text/plain">

<p>E-mail<INPUT TYPE="text" NAME="E-mail" SIZE=18>

<p>Number<INPUT TYPE="text" NAME="Number" SIZE=18>

<BR>

<INPUT TYPE="submit" VALUE="Submit">

<INPUT TYPE="reset" VALUE="Clear">


</FORM>

</BODY>

</html>
Copy linkTweet thisAlerts:
@imageniusauthorFeb 17.2007 — Thanks!!!
×

Success!

Help @imagenius spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.18,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...