Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    Regular Coder
    Join Date
    Jun 2009
    Posts
    144
    Thanks
    3
    Thanked 20 Times in 20 Posts

    Make script work on load

    I am trying to make the following fill the value box when the page loads as opposed to pressing the button. I cant seem to do it. Any ideas??

    PHP Code:
    <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 type="text" size=18 name="output">
    <input type="button" value="Generate Password" onClick="populateform(this.form.thelength.value)"><br />
    <b>Password Length:</b> <input type="text" name="thelength" size=3 value="7">
    </form> 

  • #2
    Senior Coder xelawho's Avatar
    Join Date
    Nov 2010
    Posts
    2,969
    Thanks
    56
    Thanked 557 Times in 554 Posts
    like this?

    Code:
    <html>
    <head>
    </head>
    <body onload="populateform(document.pgenerate.thelength.value)">
    <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 type="text" size=18 name="output">
    <b>Password Length:</b> <input type="text" name="thelength" size=3 value="7">
    </form>
    </body>
    </html>

  • Users who have thanked xelawho for this post:

    itxtme (12-31-2011)

  • #3
    Regular Coder
    Join Date
    Jun 2009
    Posts
    144
    Thanks
    3
    Thanked 20 Times in 20 Posts
    Legend, thanks heaps! Now to learn the code~!


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •