i am trying to validate a spring mvc form having spring tags with Jquery but this validation isn't working,need urgent help. The following JS files are being used.
On inspection i am able to see that the values are getting passed by the element id's but the validation and the error messages are not working. Please help as i am not very well versed with Jquery. Your help would be much appreciated.
<script type="text/javascript">
function submitForm()
{
$("#savelogin").validate({
rules:
{
UName:
{
required: true,
minlength: 6,
maxlength: 40
},
pwd:
{
equired: true,
minlength: 6,
maxlength: 40
}
},
messages:
{
UName:
{
required: "username is required!",
minlength: "username must be at least 6 characters long"
},
pwd:
{
required: "Please enter a password",
minlength: "Password must be at least 6 characters long"
}
},
submitHandler: function(form)
{
form.submit();
}
});
}
</script>
<title>Login Page</title>
</head>
<body>
<form:form commandName="userLogin" id="savelogin">
<fieldset>
<c:url value="/Registration.do" var="url"/>
<a href="<c:out value='${url}'/>">New User:Register</a>
<div>
<form:label path="userRegistration.userName" ><spring:message code="label.username"/> </form:label>
<form:input path ="userRegistration.userName" autocomplete="on" id="UName" />
<form:errors path="userRegistration.userName"></form:errors>
</div>
<div>
<form:label path="userRegistration.password"><spring:message code="label.password"/></form:label>
<form:password path="userRegistration.password" id="pwd"/>
<form:errors path="userRegistration.password"></form:errors>
</div>
<div>
<input type="submit" value="<spring:message code="label.login"/>" name="loginUser" id="submit" onclick="submitForm();"/>
</div>
</fieldset>
</form:form>
</body>
$(document).ready(function(){
$("#savelogin").validate({
rules:
{
UName:
{
required: true,
minlength: 6,
maxlength: 40
},
pwd:
{
equired: true,
minlength: 6,
maxlength: 40
}
},
messages:
{
UName:
{
required: "username is required!",
minlength: "username must be at least 6 characters long"
},
pwd:
{
required: "Please enter a password",
minlength: "Password must be at least 6 characters long"
}
},
submitHandler: function(form)
{
form.submit();
}
});
});
I tried with this but nothing happened. Please check and help.