• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 302
  • Last Modified:

Jquery validation by class

Hello experts.
I need help to validate a form in a modal window by classname using jquery validation plugin.
My form is  id="formcategories"
My required textfields : class="categoryclass"

If one of the textfields doesn't pass the validation - add to this class error (like i would handle this with id validation)
Attached my code
var editcategory = function(id){
    var p = $("#popuploader");
    p.dialog({
        autoOpen: false,
        width: 300,
        height: 300
    });
    p.dialog({
       buttons: {
            "Save": function () {
                var targetUrl = "index.cfm";
                var b = $("#formcategories");
                var a = b.valid();
                if (a) {
                    var f = b.serialize();
                    $.post("actions/actupdate.cfm", f, function (g) {
                        if (g) {
                            
							window.location.href = targetUrl;
                           
                        }
                    })
                }
            
            },
            "Cancel": function () {
                $(this).dialog("close");
                $(this).dialog("destroy");
            }
        }
    });
	p.dialog("open");
	p.load("forms/frmtext.cfm?categoryid=" + id, function (c, e, d) {
            if (e == "success") {
			 $("#formcategories").validate({
				 
				 }
			   )
	
            } else {
                alert("errorload")
            }
        });
};

Open in new window


Any help?
0
Panos
Asked:
Panos
  • 3
1 Solution
 
designatedinitializerCommented:
This will will add the rule "required" to all fields of class "categoryclass":

$.validator.addClassRules({
  categoryclass: {
    required: true
  }
});

Open in new window


you can add more rules inside that.
0
 
PanosAuthor Commented:
Hi designatedinitializer
where do i have to place this code inside my script so that the form will be validated on:
var a = b.valid();
0
 
PanosAuthor Commented:
Finally i got it.
Thank you for your help
0
 
PanosAuthor Commented:
thank you
regards
panos
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now