I'm trying to create a simple javascript password generator that spits out the number of characters the user puts in. So, lets say you enter the number 7. I want the program to then spit out 7 random characters from the possibilities variable. Below is my code so far:
var possibilities = ['A', 'B', 'C', 'D', 'E', 'F', 'H', 'I', 'J', 'K', 'L',
'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X',
'Y', 'Z', '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', 0, 1, 2, 3, 4, 5, 6, 7, 8, 9
];
var special_chars = "~`!#$%^&*+=-[]\\\';,/{}|\":<>?"; //no special characters
function generator() {
if (document.getElementById("input").value == '' || document.getElementById("input").value > 61) {
alert("Enter under 61 characters");
} else if (isNaN(document.getElementById("input").value) || document.getElementById("input").value == special_chars) {
alert("Enter numbers only");
} else {
//var userInput = document.getElementById("input").value -- get value of this when clicked, spit out number of items from this array based on the value collected
for (var x = 0; x < possibilities.length; x++) {
var content = possibilities[Math.floor(Math.random() * possibilities.length)];
}
document.getElementById("random_password").innerHTML = content;
}
}
I'm a bit new to JavaScript and am kind of stuck here so any help is appreciated :) Thx in advance!