my html
<div class="container">
<form action="">
<div><tr>
<label for="input1"> Password length:</label>
<input type="number" id="passwordlen">
<button onclick="Password()">submit</button></tr>
</div>
<div><tr>
<p>Password</p>
<div> <input type="text" id="passgen"> </div></tr>
</div>
</form>
</div>
my javascript
var strings = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz1234567890!@#$&"
// var passlen = document.getElementById('input1').value
// passlen = parseInt(passlen)
// console.log(passlen)
function Password() {
console.log("abc")
var passlen = document.getElementById("passwordlen").value
console.log(passlen)
var password = '';
for (i = 0; i <= passlen - 1; i++) {
let rand_num = Math.floor(Math.random() * 66);
password = password + strings[rand_num];
}
console.log(password)
document.getElementById('passgen').value = password;
}
when i click submit it prints on console as well as screen but also gets refreshed so results are not visible. There is no error message. Also i tried to add script tag before and once before .