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 6554251
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T12:40:40+00:00 2026-05-25T12:40:40+00:00

I am using jquery validate plugin to validate dynamically loaded form. For some cases

  • 0

I am using jquery validate plugin to validate dynamically loaded form. For some cases I’m loading the content using $.post and in the callback I call a function that adds the validation rules. That works. For some content, I am using $.get and in that callback I am also calling a function that adds the validation rules. However, when using $.get the form is not validated at all.

What is my problem? Is there really any kind of difference using post and get in this perspective?

I think this is the significant code but I did add a lot of code after this in case it’s needed. This is where I call the function that adds the validation rules:

  $.get("http://localhost/SMICAdmin/adminactivities/admin_update_agent.php", { agent_id: $agentid }, function(data){ 
                    //Now, add the validation rules: 
                    addUpdateAgentValidation();

                    $('#dialog-modal').dialog( "option", "title", 'Uppdatera agent');
                    $("#dialog-modal").html(data).dialog("open");

This is the code loading the form:

$("#agents td").live('click',function(event)  
       { 
           //alert("Agents");
           event.preventDefault(); 

            var col = $(this).parent().children().index($(this));

            var $td= $(this).closest('tr').children('td');  
            var $agentid=$td.eq(2).text();  
            var $name=$td.eq(3).text();  

            if(col==0){

                $.get("http://localhost/SMICAdmin/adminactivities/admin_update_agent.php", { agent_id: $agentid }, function(data){ 
                    //alert("GETDONE");
                //Now, add the validation rules: 
                addUpdateAgentValidation();

                $('#dialog-modal').dialog( "option", "title", 'Uppdatera agent');
                $("#dialog-modal").html(data).dialog("open");


                });
                //and the rest of the code
                //.
                //.

Here is the function for adding the validation rules:

function addUpdateAgentValidation(){
        //alert("GETDONE 2");
                  $("#updateagentform").validate({ 
                            errorContainer: "#updateagentmessagebox",
                            errorLabelContainer: "#updateagentmessagebox ul",
                            wrapper: "li", debug:true,


                            rules: { 


                              email1: {// compound rule 
                               // required: true, 
                                email: true 


                              }, 
                              email2: {
                                  //  required: true, 
                                    equalTo: "#email1"
                              },
                              username: {
                                //  required: true,
                                  remote: "http://localhost/SMICAdmin/smicsoap/soap_is_agentusername_available.php"

                              },
                              password: {
                              //    required: true                                 
                              },

                              password2: {
                                  //required: true,
                                  equalTo: "#password1"
                              }
                            }, 
                            messages: { 

                              email1: {// compound rule 
                                email: "Korrekt emailadress saknas"

                              }, 
                              email2: {
                                    equalTo: "Mailadresserna matchar inte varandra"
                              },
                              //username: "Anv‰ndarnamnet mÂste vara unikt"
                              username: {
                                  remote: "Användarnamn finns redan"
                              },


                              password2: {
                                  equalTo: "Lösenord inte lika"
                              }
                            }
                          }); 
                    };

And this is where where I post the form:

$("#updateagentform").live("submit", function(e){
                //Prevent the form from submitting normally

            // alert("Trying to submit user update");

             e.preventDefault();

            $.post("http://localhost/SMICAdmin/adminactivities/admin_update_agent.php",$(this).serialize(),function(msg){
                //alert the response from the server
                //alert(msg);
                $("#dialog-modal").dialog("close");

             });
             $("#usertable").empty();
             $('#usertable').load("http://localhost/SMICAdmin/adminactivities/admin_load_agents.php"); 
             $("#modalarea").empty();
             $('#modalarea').css("visibility","hidden");
       });

And the code generating the form:

echo "<div class='errormessage' id='updateagentmessagebox'> 
                <ul></ul> 
            </div> 
            <form id='updateagentform' method='post'> 
                Ändra önskade fält<br/>
                * Förnamn: <input type='text' name='firstname' /> <br/>
                * Efternamn: <input type='text' name='surname' /> <br/>
                * Email: <input id='email1' type='text' name='email1' /> <br/>
                * Repetera email: <input id='email2' type='text' name='email2' /> <br/>

                * Användarnamn: <input id='username_ID' type='text' name='username' /><br/>
                * Lösenord: <input id='password1' type='text' name='password' /><br/>
                * Repetera lösenord: <input id='password2' type='text' name='password2' /><br/>";
       foreach ($roles as $key=>$role) {
           if(in_array($key, $role_ids)){
               echo "<input type='checkbox' name='rid".$key."' value='rid".$key."' checked />".$role."<br/>";
           }else{
               echo "<input type='checkbox' name='rid".$key."' value='rid".$key."' />".$role."<br/>";
           }

       }

       echo "<input id='submitupdateagentform' type='submit' value='Uppdatera agent' /></form>";

What is my problem and how do I fix it?

  • 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-25T12:40:41+00:00Added an answer on May 25, 2026 at 12:40 pm

    You’re calling .validate() on a form that doesn’t exist on the page yet.

      $.get("http://localhost/SMICAdmin/adminactivities/admin_update_agent.php", { agent_id: $agentid }, 
        function(data){ 
            // form does not exist in DOM here
            addUpdateAgentValidation();
    
            $('#dialog-modal').dialog( "option", "title", 'Uppdatera agent');
            // form exists after this line.
            $("#dialog-modal").html(data).dialog("open");
        });
    

    You need to rearrange your function call so that .validate() gets called after the form gets appended to the DOM:

      $.get("http://localhost/SMICAdmin/adminactivities/admin_update_agent.php", { agent_id: $agentid }, 
        function(data){ 
            $('#dialog-modal').dialog( "option", "title", 'Uppdatera agent');
    
            $("#dialog-modal").html(data).dialog("open");
            addUpdateAgentValidation();
        });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm using the jQuery validate plugin to validate a multi-step form like this one:
I'm using the jQuery validate() plugin for some forms and it goes great. The
i'm using jQuery validate() plugin to validate a form. it does the validation but
I am using jquery-1.4.2 library and jquery.validate.js plugin to validate a very simple form.
I'd like to validate a form using the jquery validate plugin, but I'm unable
I'm using jquery.validate plugin and facing the following situation: <form id=myForm ....> <input type=text
I'm using the jQuery validate plugin to validate a form with a lot of
I'm using the jQuery.validate() plugin for a form. However the form contains a fieldset
I'm using jQuery's validation plugin and looking to validate many dynamically added text fields
Im using jQuery validate plugin and every form has multiple validation levels. level is

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.