Solved

Jquery validation by class

Posted on 2012-03-24
4
296 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 500 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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

The task A number given should be formatted for easy reading by separating digits into triads. Format must be made inline via JavaScript, i.e., frameworks / functions are not welcome. So let’s take a number like this “12345678.91¿ and format i…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

730 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