Home Articles FAQs XREF Games Software Instant Books BBS About FOLDOC RFCs Feedback Sitemap
irt.Org
#

Q1431 How can I create a random set of numbers/letters/characters into a form text box for use as a random password?

You are here: irt.org | FAQ | JavaScript | Number | Q1431 [ previous next ]

Try:

<form name="myform">
<input type="text" name="password">
</form>

<script language="JavaScript"><!--
var choice = "1234567890abcdefghiklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXTZ";
var size_of_password = 8;
var password = '';
for (var i=0; i<size_of_password; i++) {
  var rnd = Math.floor(Math.random() * choice.length);
  password += choice.substring(rnd,rnd+1);
}

document.myform.password.value = password;
//--></script>

©2018 Martin Webb