I am trying to do a basic password matching on button click. Below is the input and the button and the script. All i want to do is on button click check if the password = test123
. If yes then show a alert and then hide the div
.
When i click the button nothing happens. I know that the script is being executed. if i change alert(document.getElementById('passbox1').value);
to alert("starting");
i see the alert.
<div id="passdiv">
<input name="passbox1" type="password" /> <input name="submit" onclick="showDiv()" type="button" value="Submit" /></div>
<div id="list">testing</div>
<script>
function showDiv() {
alert(document.getElementById('passbox1').value);
if( document.getElementById('passbox1').value == "test123") {
alert("match");
document.getElementById('passdiv').hidden = true;
document.getElementById('list').hidden = false;
} else {
alert("Password is incorrect.");
}
}
</script>