12 September 2016

JSP Validate Form Login với Javascript Java NetBeans


login.jsp
Java 2016
<%-- 
    Document   : login
    Created on : Sep 12, 2016, 4:04:53 PM
    Author     : Lonely
--%>

<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>Login</title>

        <script type="text/javascript">
            function validate()
            {
                var a = document.getElementById("a");
                var b = document.getElementById("b");
                var valid = true;
                if (a.value.length <= 0)
                {
                    alert("Username không được để trống!");
                    valid = false;
                }
                else if(b.value.length < 6){
                    alert("Password it nhat 6 ki tu");
                    valid = false;
                }
                return valid;
            };
        </script>

    </head>
    <body>
        <h1> Login Validate</h1>
        <form action="home.jsp" method="POST"  onsubmit="return validate();">
            Username:<input type="text" name="user" value="" id="a"/><br/>
            Password:<input type="text" name="pass" value="" id="b"/><br/>
            <input type="submit" value="Login"/>
        </form>
    </body>
</html>

0 nhận xét:

Post a Comment

 

BACK TO TOP

Xuống cuối trang