Issue
I have been working on a little coding project for my friends. This includes a somewhat password system that changes your username. I implemented this so that impersonation was harder to do.
<main class="join-main">
<label for="password">Password</label>
<input
type="password"
name="password"
id="password"
placeholder="Enter password..."
required
/>
<button type="button" onclick="fn1()">Check ig</button>
<script>
function fn1() {
let pswvalue = document.getElementById("password").value
if (pswvalue = "1234") {
document.getElementById("username").value = "Hello"
} else {
return;
}
}
</script>
<form action="chat.html">
<div class="form-control">
<label for="username">Logging Into:</label>
<input
type="text"
name="username"
id="username"
placeholder="The User you are logging into will appear here."
readonly
/>
For some reason, even if the password isn't "1234", The username still changes to Hello. Any suggestions on how to fix?
Solution
It should be if (pswvalue === "1234")
since we are comparing two stings.
Answered By - Han Moe Htet
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.