Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Jquery validation by class

Posted on 2012-03-24
4
Medium Priority
?
300 Views
Last Modified: 2012-03-26
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
Comment
Question by:Panos
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
4 Comments
 
LVL 7

Accepted Solution

by:
designatedinitializer earned 2000 total points
ID: 37760544
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
 
LVL 2

Author Comment

by:Panos
ID: 37760698
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
 
LVL 2

Author Comment

by:Panos
ID: 37765545
Finally i got it.
Thank you for your help
0
 
LVL 2

Author Closing Comment

by:Panos
ID: 37765547
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!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Having worked on larger scale sites, we found out that you are bound to look at more scalable solutions to integrating widgets, code snippets or complete applications and mesh them into functional sites, in any given composition. To share some of…
This article discusses how to implement server side field validation and display customized error messages to the client.
Learn the basics of lists in Python. Lists, as their name suggests, are a means for ordering and storing values. : Lists are declared using brackets; for example: t = [1, 2, 3]: Lists may contain a mix of data types; for example: t = ['string', 1, T…
Learn the basics of if, else, and elif statements in Python 2.7. Use "if" statements to test a specified condition.: The structure of an if statement is as follows: (CODE) Use "else" statements to allow the execution of an alternative, if the …
Suggested Courses

618 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question