I have been struggling to develop a JavaScript program that can generate a random number multiple times based on user input. Despite numerous attempts, I haven't been able to get it to work.
Below is the code snippet I've been working with:
function generateRandomString() {
var totalIterations = parseInt(document.getElementById('input').value);
var output = document.getElementById('output');
output.innerHTML = '';
var chars = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXTZabcdefghiklmnopqrstuvwxyz";
var string_length = 8;
var randomstring = '';
for (var i = 0; i < string_length; i++) {
var rnum = Math.floor(Math.random() * chars.length);
randomstring = randomstring + chars.substring(rnum, rnum + 1);
for (var j = 0; j <= totalIterations; j++) {
var item = document.createElement('div');
item.innerHTML = randomstring;
output.appendChild(item);
}
}
}
<form name="randform">
<input type="button" id="input" value="Create Random String"
onClick="generateRandomString();">
<input type="text" name="randomfield" value="">
</form>
<div id="output"></div>