Reputation: 1
Hi I have got many text fields to validate, but I don't want to use class "required" that is required by Jquery to validate text fields because I am using my own class css class for presentation reasons. So I can't use required class.
$(document).ready(function(){
$("#dform").validate({
errorPlacement: function(error, element) {
return true;
},}
jQuery.validator.addClassRules({
txt: {
required: true
}
});
});
});
I am using below code to validate fields that have class "txt". "txt" is my css class for text fields. Could you help me what is the error in this code? Firefox firebug gives an error like missing) after argument list.
Upvotes: 0
Views: 345
Reputation: 1021
bdesham addressed the issue with using "required" as a class name.
As to your error, this is probably what you wanted to do:
$(document).ready(function(){
$("#dform").validate({
errorPlacement: function(error, element) {
return true;
}
});
jQuery.validator.addClassRules({
txt: {
required: true
}
});
});
If you're a javascript novice, do yourself a favor and use an IDE that can check javascript syntax, or use an online syntax validator; it'll save you lots of time/headaches.
Upvotes: 0
Reputation: 16089
You know you can use multiple classes in HTML, right?
<input type="text" name="whatever" class="txt required"/>
As long as required
isn’t a class name that will conflict with your stylesheet, you can just use both classes. Your CSS will happily ignore the required
and jQuery will happily ignore the txt
.
Upvotes: 1