Cant see error messages on the screen for jquery validation
Please help me, I dont know where I am going wrong. I cant see any error messages when I click on submit.
Here is the code-
<%@ taglib uri="http://jakarta.apache.org/struts/tags-html"
prefix="html"%>
<%@ taglib uri="http://jakarta.apache.org/struts/tags-bean"
prefix="bean"%>
<%@ page language="java" contentType="text/html; charset=I开发者_开发问答SO-8859-1"
pageEncoding="ISO-8859-1"%>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Login</title>
<script src="http://code.jquery.com/jquery-latest.js"></script>
<script type="text/javascript" src="http://dev.jquery.com/view/trunk/plugins/validate/jquery.validate.js"></script>
<script type="text/javascript">
$(document).submit(function(){
$("#LoginForm").validate({
errorPlacement: function(error,element){
return true;
},
rules: {
"loginName": {
required: true,
minlength: 5
},
"password":{
required: true,
minlength: 5
}
},
messages:{
"loginName":{
required:"Email must be supplied",
minlength:"specify at least 5 characters"
},
"password":{
required:"Email must be supplied",
minlength:"specify at least 5 characters"
}
}
});
});
</script>
</head>
<body>
<form id="LoginForm" name="LoginForm"
action="SignIn.do" method="post"
enctype="multipart/form-data" >
<table bordercolor="#FFFF33" border="10" height="100%" width="100%">
<tr valign="top">
<td>
<table align="top">
<tr>
<td>User Name</td>
<td><input type="text" id="loginName" name="loginName" /></td>
</tr>
<tr>
<td>Password</td>
<td><input type="password" id="password" name="password" /></td>
</tr>
<tr>
<td>
<input type="submit" name="submit" />
</td>
</tr>
</table>
</td>
</tr>
</table>
</form>
</body>
Since you're specifying an errorPlacement
function, it's up to you to insert the error message in the document.
Your errorPlacement
function does nothing, so the error message won't be inserted anywhere. You'll need to either remove errorPlacement
to get the default behavior, or modify it so it inserts its first argument somewhere in the document.
You can find more information about errorPlacement
and the other validation options here.
精彩评论