Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

creating random numbers

Status
Not open for further replies.

altaratz

ISP
Apr 15, 2001
73
US
I'm trying to generate a random number in a Perl script (confirmation #), and I would like to populate the field of a generated form with the random number. I'm using a random # generating Javascript as follows in the printed HTML in my Perl statement:

print "Content-type: text/html\n\n" unless

$content_type_printed++;

print qq!
<html><head><title>Coupons</title></head> <form method=&quot;POST&quot; action=&quot; <input type=&quot;hidden&quot; name=&quot;confirmnumber&quot; value=&quot;<SCRIPT language=&quot;JavaScript&quot;><!--
var maxNumber = 1000;
var randomNumber = Math.round(maxNumber * Math.random());
//--></SCRIPT>

<SCRIPT language=&quot;JavaScript&quot;><!--
document.write(randomNumber);
//--></SCRIPT>


</td></tr>


Now I know that a form can't take a Javascript as a &quot;value&quot; - however, I'm at a loss for how to get the random number in there (I need to do it at this step, so that both people I've got receiving email verfication get the same number) - thanks for any suggestions.

Ethan Altaratz
 
Since you are generating the page via a script, why don't you generate the random number via perl and substitute it's value when you print the html? Something like this:
Code:
$confirmnumber = int(rand(1000));
print qq!<input type=&quot;hidden&quot; name=&quot;confirmnumber&quot; value=&quot;$confirmnumber&quot;>!;
Meddle not in the affairs of dragons,
For you are crunchy, and good with mustard.
 
Actually, pull the JScript out of the input statement, replace it by setting the value of the field to your random number function.

Rose/Miros


 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top