Hello, I found your code to be helpful but I am facing an issue. I want to display a message using innerHTML when the passwords do not match. I have been trying to implement this feature but it is not working for me. Below is my current code. Please provide guidance as I am still learning.
if (pwd != cpwd) {
document.getElementById("pwd").innerHTML = "Password must match";
document.getElementById("cpwd").innerHTML = "Password must match";
document.getElementById("pwd").style.color = "RED";
return false;
}
I would like to understand how to correctly use innerHTML.
Your code snippet:
<input id="pass1" type="password" placeholder="Password" style="border-radius:7px; border:2px solid #dadada;" /> <br />
<input id="pass2" type="password" placeholder="Confirm Password" style="border-radius:7px; border:2px solid #dadada;"/> <br />
<script>
function myFunction() {
var pass1 = document.getElementById("pass1").value;
var pass2 = document.getElementById("pass2").value;
if (pass1 != pass2) {
document.getElementById("pass1").style.borderColor = "#E34234";
document.getElementById("pass2").style.borderColor = "#E34234";
}
else {
alert("Passwords Match!!!");
}
}
</script>
Submit
Thanks in advance for your support and looking forward to your response.