<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Javascript form validation</title>
</head>
<body>
<script>
    function validateform() {
        var name = document.singinform.name.value;
        var password = document.singinform.password.value;
        if (name == null || name == "") {
            document.getElementById("error").innerHTML = "Name Can't be blank";
            return false;
        } else if (password.length < 6) {
            document.getElementById("error").innerHTML = "Paasword must me 6 digit";
            return false;
        }
        else if (password == "password") {
            document.getElementById("error").innerHTML = "password could not be same as password";
            return false;
        }
        else if (password == "") {
            document.getElementById("error").innerHTML = "password could not be same as password";
            return false;
        }
    }  
</script>

<body>
    <div id="error"></div>
    <form name="singinform" method="post" onsubmit="return validateform()">
        <div>
            <label for="Name">Name</label>
            <input type="text" name="name"><br />
        </div>
        <div>
            <label for="password">Password</label>
            <input type="password" name="password"><br />
        </div>
        <input type="submit" value="signin">
    </form>
</body>
</html>
Leave a Comment