Search code examples
javascriptconditional-statementsshow-hide

Javascript conditional hiding and showing


Hello guys I'm confused with javascript code, I want a program that gets the input from the user, and if that input matches a specific value like 1234 I want it to hide part of the form. E.g.

var x=document.getElementById('pin').value;

    function hidden() {
      if (x.value=1234){
    	  document.getElementById('pin').style.display="none";
      }
    }
<input type="number" name="pin" placeholder="Please Enter Your Pin" id="pin">
<button onclick="hidden()">Enter</button>


Solution

  • var x=document.getElementById('pin');
    
    function checkPin() {
      if (x.value == "1234"){
          x.style.display="none";
      }
    }
    <input type="number" name="pin" placeholder="Please Enter Your Pin" id="pin" />
    <button onclick="checkPin()">Enter</button>