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 Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Random number generator

Status
Not open for further replies.

Killborg

Technical User
Jul 16, 2007
46
US
Hello,
I am new to javascript and I am working on a web page that has a random number password generator. The random number get generated when you click on the button. But what I would like to do is have the button selected when the page opens putting the random number into the field. Can any one help me with this issue. The button name is "GetNumber" and the field the number is entered into is "YourNumber"

Or can the button be eliminated and the random number is generated when the page is opened?

Thanks
 
normally when you click a button it calls a function as defined in the onclick handler on the button, something like this:
Code:
<script type="text/javascript">

function [!]someFunction()[/!] {
   alert("I do something");
}

</script>

<input type="button" value="click me" onclick="[!]someFunction()[/!]" />

if you don't want to wait for the button to be clicked to trigger that function, and instead just have the function execute when the page loads then you would define that in the onload event for the window:
Code:
<script type="text/javascript">

function [!]someFunction()[/!] {
   alert("I do something");
}

window.onload = [!]someFunction[/!];

</script>

-kaht

Lisa, if you don't like your job you don't strike. You just go in every day and do it really half-assed. That's the American way. - Homer Simpson
 
Thank You for the input. But one question. Can the action be triggered without the alert message. I just need it to select the button with no message.

Thanks
 
Killborg, kaht gave you that code as a sample, not for you to copy and use verbatim.

[monkey][snake] <.
 
Hello,
Since I am new to javascript I am still trying to understad this. So here is what I have done.

<input name="Order_Conformation_Number" type="text" id="Order_Conformation_Number" size=18 />
<input name="button" type="button" onclick="populateform(this.form.thelength.value)" value="Select to Generate Conformation Number" />

so where do I insert the code?
 
Hello,
Since I am new to javascript I am still trying to understad this. So here is what I have done.

<input name="Order_Conformation_Number" type="text" id="Order_Conformation_Number" size=18 />
<input name="button" type="button" onclick="populateform(this.form.thelength.value)" value="Select to Generate Conformation Number" />

so where do I insert the code?
I would like this to happen when the page loades
 
If you are going to use the number as an Order Confirmation number then I would be a little careful to ensure that you don't get duplicates being generated, you may be better if that is the case to use a SEQUENCE or similar functionality in the database to generate the number.

Greg Griffiths
Livelink Certified Developer & ECM Global Star Champion 2005 & 2006
 
I agree with Greg. If you are generating what is to be a unique number, then use a server-side process to do this. Otherwise two or more customers could get the same confirmation number.

Adam
 
Thank You For the information.
But I used Order Confirmation number and Select to Generate Conformation as an example.
I am just trying to figure out where to insert the
code to select the button when the button when the
page opens.
 
Thank You for the information adam0101.
So simple just seeing it know makes sense to me.
Just got so frustrated could not think straight.

Thanks Again
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top