random number generator

Discussion in 'JavaScript' started by aiden857, May 20, 2007.

  1. #1
    hi all im trying to put together a random number generator. it's working fine but i want to be able to have a name field that when filled in it will be the start of the random number. here's what i have so fare.

    <script>

    var keylist="abcdefghijklmnopqrstuvwxyz123456789"
    var temp=''

    function generatepass(plength){
    temp=''
    for (i=0;i<plength;i++)
    temp+=keylist.charAt(Math.floor(Math.random()*keylist.length))
    return temp
    }

    function populateform(enterlength){
    document.pgenerate.output.value=generatepass(enterlength)
    }
    </script>

    <form name="pgenerate">
    <input name="output" type="text" onFocus="populateform(this.form.thelength.value)" size=18 readonly="">
    <input type="hidden" name="thelength" size=3 value="10">
    <input type="text" name="name">

    </form>
     
    aiden857, May 20, 2007 IP
  2. ajsa52

    ajsa52 Well-Known Member

    Messages:
    3,426
    Likes Received:
    125
    Best Answers:
    0
    Trophy Points:
    160
    #2
    Could you put an example of what you want to put on that field.
    I don't understand your sentence: "...with the start of the random number".
     
    ajsa52, May 21, 2007 IP
  3. Aztral

    Aztral Well-Known Member

    Messages:
    344
    Likes Received:
    15
    Best Answers:
    0
    Trophy Points:
    125
    #3
    I'm not understanding what you want either. It looks to me like the code is producing a random string of length thelength.value.

    In the example above thelength.value = 10. So you want to prepend "10" to string?

    Or you want a control on form to input a number, and use that number to get a string of the length of that number?
     
    Aztral, May 22, 2007 IP