JS登入驗證null

talNot發表於2018-07-01
---
title: JS表單驗證
---
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
```
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<head>
    <title>Student</title>
    <script language="JavaScript">
        function checkForm() {
            var username = document.getElementById("usernameid").value;
            var password = document.getElementById("passwordid").value;
            if((username=null || username=='') &&(password=null || password=='')){
                alert("使用者名稱或密碼不能為空");
                return false;
            }else {
                return true;
            }
        }
    </script>
</head>
<body>
<form method="post" name="myform">
   
            UserName:<input type="text" name="username" id="usernameid" ><br>
            PassWord:<input type="password" name="password"  id="passwordid"><br>
            <input type="submit" value="登入" οnclick="return checkForm();">
            <input type="reset" value="重置" >
</form>

</body>
<%
    
 %>
<jsp:forward page="success.jsp"></jsp:forward>

</html>

```

相關文章