Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4611062
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T01:13:03+00:00 2026-05-22T01:13:03+00:00

I’m trying to set up a remote validation with the jQuery validation plugin 1.8.0

  • 0

I’m trying to set up a remote validation with the jQuery validation plugin 1.8.0 (and JQuery 1.5.2).

It works fine for “required” and “maxlength” but the remote validation works ONLY after the 2nd click (validation), or if any of the other errors has been fired before.

The validation is performed correctly and an error message is displayed but the first time, the validation returns true (even if an error is displayed). This is a problem since the form will be submitted with an error.

Here is my code (simplified):

<script type="text/javascript">
    $(function() {
         $( "#check" ).click(function(){
            var valid = $("#myForm").validate(
                 {rules: {
                       groupName:{
                            required:true,
                            maxlength:40,
                            remote: {
                                url: 'ajaxCheck.php', // returns always a dummy string: "Simulate an error message" (JSON encoded)
                                type: "post",
                                data: {
                                    groupName: function() {
                                            return $("#groupName").val()
                                    }
                                }
                            }
                        }

                    }
                }
            ).form();
            alert(valid); // Returns true at the first call, and then false
        });
    });
</script>

<form id="myForm" action="">
   <label for="groupName">Group name</label>
   <input type="text" maxlength="40" size="45" value="my test" id="groupName" name="groupName">
</form>
<input type="button" value="Check form"   id="check" >

The ajaxCheck.php contains:

require_once ('Zend/Json/Encoder.php');
echo Zend_Json_Encoder::encode("Simulate an error message");

The JSON response seems to be correctly encoded (checked with Firebug).

Any idea what I’m doing wrong?

I tried also jQuery 1.6 but had other problems on IE8.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-22T01:13:03+00:00Added an answer on May 22, 2026 at 1:13 am

    You are not waiting for validation to occur before using the return value. The reason is that validation requires an ajax request, and you’re not waiting for it. The proper way to do this is to include any code you want to run after validation inside of a callback. In the validation plugin there is an invalidHandler that is called when the validation fails. You use it by adding it to the options object that you pass to validate() like so:

    $(function() {
             $( "#check" ).click(function(){
                var valid = $("#myForm").validate(
                     {rules: {
                           groupName:{
                                required:true,
                                maxlength:40,
                                remote: {
                                    url: 'ajaxCheck.php', // returns always a dummy string: "Simulate an error message" (JSON encoded)
                                    type: "post",
                                    data: {
                                        groupName: function() {
                                                return $("#groupName").val()
                                        }
                                    }
                                }
                            }
                        },
                        invalidHandler: function(form, validator){
                                alert('invalid input'); //note this is called ONLY IF validation fails
                        }
                    }
                ).form();
            });
       });
    

    The validation plugin has a number of callbacks that are called based on validation results. Take a look at them here (click on “options” and look for functions that are “callbacks”.)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to loop through a bunch of documents I have to put
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have a bunch of posts stored in text files formatted in yaml/textile (from
We're building an app, our first using Rails 3, and we're having to build
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
I'm making a simple page using Google Maps API 3. My first. One marker
I have some data like this: 1 2 3 4 5 9 2 6

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.