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>
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):