简体   繁体   中英

I created two text boxes called username and password using html and i want to check the username and password matched or not using javascript

<script type="text/javascript">
  function buttonclick(){
    if(document.getElementById("txt1").value==document.getElementById("txt2").value){
      alert("user name and password are matched");
    }
    else{
      alert("user name and password are not matched");
    }
  }

  </script>

field.setCustomValidity("Invalid field."); will make the field invalid.

 function buttonclick(){ if(document.getElementById("txt1").value==document.getElementById("txt2").value){ alert("user name and password are matched"); document.getElementById("txt2").setCustomValidity("Invalid field."); } else{ alert("user name and password are not matched"); } }
 Username: <input type="text" name="username" id="txt1"><br> Password: <input type="text" name="Password" id="txt2"><br> <button type="button" onclick="buttonclick()">Click Me!</button>

<!DOCTYPE html>
<html>
<head>
</head>
<body>
 <input type="text" placeholder="Enter the password" id="firstField"><br><br>
 <input type="text" placeholder="ReEnter the password to confirm" id="secondField"><br><br>
<button onclick="checkAction()">Submit</button>

<script>

function checkAction() {
    if(document.getElementById("firstField").value==document.getElementById("secondField").value) {
        alert("Pasword Mathced");
    } else {
        alert("Password donot matched");
    }
}

</script>
</body>
</html>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM