My javascript needs to change a variable inside a function if a radio button is clicked. I have tried couple of methods - if else statement being one of them, but nothing has worked so far.
In my last try I tried to execute a function on click where it would reset my variable declared earlier in the first function.
The whole purpose of code is to generate a random password with an option to use special symbols.
It is also meant to be a Chrome extension, so the use of inline code is forbidden.
<html>
<br>
<h1>Set the number of characters</h1>
<input id="num" type = "number" value = "20" name = "value"><br><br>
<form>
<input type="radio" type = "text" id="spec_symb" name="symbols" value="specialSymbols">
<label for="spec_symb">Use special symbols</label><br>
</form>
<button id="click">Generate</button><br>
<p id="text" ></p>
<script src="jquery-3.5.1.min.js"></script>
<script src="pass.js"></script>
</html>
function pass(length) {
var passw = "";
var symbols = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
document.getElementById("spec_symb").onclick = function(){func()};
function func(){window.symbols = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789!@#$%^&*()_"
};
var slength = symbols.length;
for ( var i = 0; i < length; i++ ) {
passw = passw + symbols.charAt(Math.floor(Math.random() * slength));
}
return passw;}
document.getElementById("click").onclick = function(){myFunction()};
function myFunction(){
document.getElementById("text").innerHTML = passw(document.getElementById("num").value);
}