I'm trying to create a function that will check the users input if it has the input of admin. It keeps on displaying correct even if its incorrect, but when I hard code the value of user input and admin it checks whether the output is correct or incorrect. I want the users to input the value and check whether it is correct or wrong.
var str = document.getElementById('user');
var str2 = document.getElementById('admin');
var reg = new RegExp(str2.value, "i");
var result = str.value.match(reg);
function sample() {
if (result) {
document.getElementById('checker').innerHTML = "correct";
} else {
document.getElementById('checker').innerHTML = "wrong";
}
}
<textarea id="admin" placeholder="admin" rows="5"></textarea>
<textarea id="user" placeholder="user" rows="5"></textarea>
<textarea id="checker"></textarea>
<br>
<button style="height: 50px; width: 100px;" onclick="sample()">Check</button>