To start generating Random numbers or passwords using JavaScript you must be familiar with random function of Math object in JavaScript. You can learn it from JavaScript Random Numbers article.
Now, to develop your own Random Password Generator in HTML using JavaScript, create a list of valid and allowed characters to generate a valid password of valid strength.
Example
var allowedChars = new String(); allowedChars = "a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z,"; allowedChars += "A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,S,T,U,V,W,X,Y,Z,"; allowedChars += "1,2,3,4,5,6,7,8,9,0,!,@,#,$,%,&,?";
Now split the above string into the form of array to place each character at array index.
var arr = new Array();
Split the string using string function split by passing the separator symbol used in the string of allowed characters.
arr = allowedChars.split(",");
Create 2 variables, 1st for storing password string concatenating it with random character picked up by the Random number generator, 2nd for getting the new random character.
var passwordString = new String(); var temp = new String();
Use the following JavaScript code for Random Password generator:
var count = document.getElementById('txtLength').value;
for (i = 0; i < count; i++) {
var rand = Math.random();
temp = Math.ceil(rand * (arr.length - 1));
passwordString += arr[temp];
}