I have a simple Register page which is :
<html>
<head>
<title>Register</title>
<link rel="stylesheet" href="css/normalize.css">
<link rel="stylesheet" href="css/style.css">
<script src="js/jquery-3.2.1.min.js"></script>
</head>
<body>
<form action="">
<div>
<label style="display: block; padding-left: 0.3em;">REGISTER</label>
</div>
<div class="emailInputDiv">
<label class="email">Email </label>
<input type="text" name="email" id="em">
</div>
<div class="passwordInputDiv">
<label class="password">Password</label>
<input type="password" name="password" id="pw">
</div>
<div class="passwordInputDiv2">
<label class="password">Confirm Password</label>
<input type="password" name="password" id="pw2">
</div>
<div style="margin-bottom: 0.5em">
<button type="submit" class="signInButton" onclick="check()">
<span>Sign In</span>
</button>
</div>
</form>
<script>
let pw = document.getElementById("pw").value;
let pw2 = document.getElementById("pw2").value;
(function () {
if(pw != pw2){
$('.passwordInputDiv').css("color", "red");
$('.passwordInputDiv > input').css("color", "red");
$('.passwordInputDiv2').css("color", "red");
$('.passwordInputDiv2 > input').css("color", "red");
}
})();
</script>
</body>
</html>
I wanna make its font color red immediately whenever password inputs change and doesnt match. that self-executing function runs when page loads, but I want it to run everytime those inputs changes.
Also those pw and pw2 is empty since its executed when page is loaded. So fucntion does not execuded.
How can I adjust this?