Home > front end >  HTML .value checking not working properly
HTML .value checking not working properly

Time:05-06

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 >

            <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 >
                    
        <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?

CodePudding user response:

It should be if (pswvalue === "1234") since we are comparing two stings.

  • Related