I have a login form that needs to be validated . It has a couple of buttons . I need to validate my form in such a way that if the user forgets values in the button then i flag an error . However on success i move to a new page to continue work . i have the following but validation is not happening .
JQ :
<script type="text/javascript">
$(function() {
$('#txtEmpid').click(
{
rules: {
txtEmpid: {
required: true
}
},
errorPlacement: function(error, element) {
element.css('background', '#ffdddd');
}
});
$('#txtPassword').click(
{
rules: {
txtPassword: {
required: true
}
},
errorPlacement: function(error, element) {
element.css('background', '#ffdddd');
}
});
});
</script>
HTML form ( index.html):
<FORM NAME="frmLogin" ACTION="Login.jsp" METHOD="post" >
<fieldset>
<div class="text-center">
<label class="text-center" for="txtEmpid">Employee Id </label>
<div class="text-center">
<input type="text" id="txtEmpid" name ="txtEmpid" placeholder="Employee Id">
</div>
</div>
<div class="text-center">
<label class="text-center" for="txtPassword">Password</label>
<div class="text-center">
<input type="password" id="txtPassword" name ="txtPassword" placeholder="Password">
</div>
</div>
<div class="text-center">
<div class="text-center">
<button type="submit" class="btn btn-primary">Sign in</button>
</div>
</div>
</FIELDSET>
The above it not working . I am sure my jquery plugins are correct as i am able to do a validation for the entire submit form by using .validate jquery method .
I want to do validate every button . If values are ok then i move to new page (Login.jsp) else i stay on index.html and flag the problem . How do i do it ? Whats my mistake ?
rulesanderrorPlacementare options/methods only for the jQuery Validate plugin and must be placed inside.validate()... they can't be arbitrarily placed inside of a.click()handler or anyplace else outside of.validate().