I am trying to write a function but having some errors. My "showPass" function is returning null
<input id="userid" type="password" value="12345">
<button id="showPassButton" onclick="showPass(userid, showPassButton)">Show</button>
<script>
function showPass(passId, btnId) {
const pass = document.getElementById('passId');
console.log(pass);
const btn = document.getElementById('btnId');
console.log(btn);
}
</script>
You have to use onclick="showPass('userid', 'showPassButton')"> instead of onclick="showPass(userid, showPassButton)"> because getElementById requires a string. Please take following snippet for reference.
function showPass(passId, btnId) {
const pass = document.getElementById(passId);
console.log(pass);
const btn = document.getElementById(btnId);
console.log(btn);
}
<input id="userid" type="password" value="12345">
<button id="showPassButton" onclick="showPass('userid', 'showPassButton')">Show</button>