going crazy here pleaase help

Discussion in 'Programming' started by aiden857, May 21, 2007.

  1. #1
    random number generator

    --------------------------------------------------------------------------------

    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 21, 2007 IP
  2. painthappy

    painthappy Peon

    Messages:
    93
    Likes Received:
    9
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Do it like this:

    
    <form name="pgenerate">
    <input name="output" type="text" size=18 readonly="">
    <input type="hidden" name="thelength" size=3 value="10">
    <input type="text" name="name">
    
    </form>
    
    <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() {
    document.pgenerate.output.value=generatepass(document.pgenerate.thelength.value)
    //}
    </script>
    
    Code (markup):
     
    painthappy, May 21, 2007 IP