Reputation: 1223
i am newbie in jquery. i searched in google and i got Validation Plugin. but it's not working. i have attached jquery.validate.js in my header part.
my code looks like...
<form action="" method="" id="contact">
<div class="form-group"">
<label> Your Name </label>
<input type="text" class="form-control" placeholder="Enter Your Name" id="firstname" required="" minlength="5"/>
</div>
<div class="form-group">
<label> Your E-mail </label>
<input type="email" class="form-control" placeholder="Enter Your Email" id="email"/>
</div>
<button type="submit" class="btn btn-primary btn-lg"> Send</button>
</form>
<script type="text/javascript">
$('#contact').validate({
success: function(label){
label.addClass("has-success").text("ok");
}
});
</script>
but it's not validating my field... Can anyone say how to use it? i know i am doing something wrong here but i am newbie so...
Upvotes: 0
Views: 455
Reputation: 3198
Try using document ready instruction:
$(function(){
$('#contact').validate();
});
it works: http://jsfiddle.net/RQMaV/15/
Upvotes: 1
Reputation: 452
The submit button is essencial since it fires the validate function:
$("#myform").validate({
submitHandler: function(form) { // this line is important
form.submit(); // with this line the validate function gets fired
}
});
perhaps you should also try following:
– make sure your jquery library is correctly embedded in your document
– make sure your validation.js is in the correct folder
Upvotes: 1
Reputation: 3323
Did you include jquery-plugin validation.js file in your project directory?? If no then you need to include http://www.websitecodetutorials.com/code/jquery-plugins/validation.js
Upvotes: 1