Development Java Javascript

What is the difference when using Javascript’s .value? [on hold]


var a = document.getElementById("my-input").value;


var a = document.getElementById("my-input");
var b = a.value;

Sometimes, when I use the former, (like when I answered a previous question here), it does not work when used in conditional statements, and I had to use the latter to get the solution to work.


Why does

function myfunction() {
        var pass = document.getElementById("passwordInput"); 

        //this returns the value of input
        if(pass.value == "correct password") {
              alert("You have logged successfully");
              //doesn't work
         var a = document.getElementById("passwordInput");
         var b = a.value;
         if(b == "correct password") {
            alert("You have logged unsuccessfully");
<input id = "passwordInput"></input>
<button onclick = "myfunction()">Submit</button>

not work?

Leave a Reply

Your email address will not be published. Required fields are marked *