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

  • Home
  • SEARCH
  • 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 6104061
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T13:47:57+00:00 2026-05-23T13:47:57+00:00

jQuery validation plugin doesn’t seem to work with my code. The text fields are

  • 0

jQuery validation plugin doesn’t seem to work with my code. The text fields are present in a table wrapped inside a form. This is a dynamic form.

$('#buttonID').live('click', function(event) {

        $('#formID').validate({
          rules: {
                firstName: "required",
                lastName: "required",
                phoneNum: {
                    required: true,
                    minlength: 10
                },
                pword: {
                    required: true,
                    minlength: 7
                },
                cpword: {
                    required: true,
                    minlength: 7,
                    equalTo: "#pword"
                },
                emailId: {
                    required: true,
                    email: true
                }
            },
            messages: {
                firstName: "Please enter firstname",
                lastName: "Please enter lastname",
                phoneNum: "Please provide a phone number",              
                pword: {
                    required: "Please provide a password",
                    minlength: "Your password must be at least 7 characters long"
                },
                cpword: {
                    required: "Please provide a password",
                    minlength: "Your password must be at least 7 characters long",
                    equalTo: "Please enter the same password as above"
                },
                emailId: "Please enter a valid email address"
            }

        });

    event.preventDefault();
});

Here is the code where I create a form on button click:

function createNewUser(event){
    //clear all the divs
                    if ($("#srchResults").length > 0){                  
                            $('#srchResults').empty();
                    }
        var htmlTable;

                    htmlTable = '<form id="userAttrC">';
                    htmlTable += '<table style="border: 0px; width: 91%;" id="createUserTable" class="rec_filters">';
                    htmlTable += '<tr><td>';
                    htmlTable += '<input type="submit" id="saveUser" class = "buttons" value="Save" >&nbsp;<input type="submit" id="cancelUser" class = "buttons" value="Cancel" >';
                    htmlTable += '</td></tr>';
                    htmlTable += '<tr>';
                    htmlTable += '<td style="width: 30%; vertical-align: top;">';
                    htmlTable += '</td>';
                    htmlTable += '<td style="width: 1%; text-align: center;">';
                    htmlTable += '</td>';
                    htmlTable += '<td style="width: 60%; text-align: left; vertical-align: top;">';

                    htmlTable += '<b>Personal Information</b><br />';
                    htmlTable += '<hr class="d">';
                    htmlTable += '<label for="salutation">Salutation:</label>';
                    htmlTable += '<select id="salutationDD" name="salutation" class="filterselect">';
                    htmlTable += '<option value=""></option>';
                    htmlTable += '<option value="Mr.">Mr.</option>';
                    htmlTable += '<option value="Ms.">Ms.</option>';
                    htmlTable += '<option value="Mrs.">Mrs.</option></select><br />';

                    htmlTable += '<label for="fname">First Name:</label>';
                    htmlTable += '<input type="text" name="fname" id="firstName" class="readOnlyIp" value="" /><br />';

                    htmlTable += '<label for="lname">Last Name:</label>';
                    htmlTable += '<input type="text" name="lname" id="lastName" class="readOnlyIp" value="" /><br />';

                    htmlTable += '<label for="suffix">Name Suffix:</label>';
                    htmlTable += '<input type="text" name="suffix" class="readOnlyIp" value="" /><br />';

                    htmlTable += '<label for="email">Email:</label>';
                    htmlTable += '<input type="text" name="email" id="emailId" class="readOnlyIp" value="" /><br />';

                    htmlTable += '<label for="country">Country:</label>';

                    htmlTable += '<select id="countryDD" name="country" class="filterselect">';

                    //get country list via ajax call
                    $.ajaxSetup({
                        async: false,   
                        "error":function() {   
                            alert("error");
                    }});
                    $.getJSON("<url>", 
                    {
                    countries: "1"
                    },
                    function(data) {

                            htmlTable += '<option value=""></option>';

                            for(var i=1; i<data[0].length; i++){               
                                htmlTable += '<option value="'+data[0][i]+'">'+data[0][i]+'</option>';
                            }
                    });
                    htmlTable += '</select><br />';

                    htmlTable += '<label for="phone">Phone Number:</label>';
                    htmlTable += '<input type="text" name="phone" id="phoneNum" class="readOnlyIp" value="" /><br />';

                    htmlTable += '<label for="ext">Phone Extension:</label>';
                    htmlTable += '<input type="text" name="ext" class="readOnlyIp" value="" /><br />';

                    htmlTable += '<label for="cell">Cell Phone:</label>';
                    htmlTable += '<input type="text" name="cell" class="readOnlyIp" value="" /><br />';

                    htmlTable += '<label for="pwd">Password:</label>';
                    htmlTable += '<input type="text" name="pwd" id="pword" class="readOnlyIp" value="" /><br />';
                    htmlTable += '<label for="cpwd">Confirm Password:</label>';
                    htmlTable += '<input type="text" name="cpwd" id="cpword" class="readOnlyIp" value="" /><br />';
                    htmlTable += '</td></tr>';
                    htmlTable += '</table>';
                    htmlTable += '</form>';

     $('#srchResults').append(htmlTable);       
    event.preventDefault();
}
$("#createUser").click(function(event){ createNewUser(event); }); 
  • 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-23T13:47:57+00:00Added an answer on May 23, 2026 at 1:47 pm

    adding the validation rules on the button is ok, especially if on document ready, your form doesn’t exist yet, without seeing your entire page code it’s hard to say what the BEST place to do it is though. Likely in the success handler of your ajax call that loads your form.

    anyway, the point is, in your button handler, you need to actaully tell the form to validate! like so:

    $('#formID').valid();
    

    this is what i ussually do:

    if($('#formId').valid()){
        //do your form posting logic here
    }
    else{
       //anything special you want to do with an invalid form
    
    }
    

    EDIT:

    ok, put your $(‘#FormId’).validate() stuff right after:

    $('#srchResults').append(htmlTable); 
    

    and then have:

     if($('#formId').valid()){
            //do your form posting logic here
        }
        else{
           //anything special you want to do with an invalid form
    
        }
    

    inside this:

    $('#buttonID').live('click', function(event) {
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

jQuery's draggable functionality doesn't seem to work on tables (in FF3 or Safari). It's
ASP.NET MVC's Html.BeginForm() seems to work with jQuery validation plugin but the validation plugin
I am using jquery validation plugin for form validation. I have added a custom
I use the JQuery Validation plugin to validate a form ( http://docs.jquery.com/Plugins/Validation/ ) For
at the moment i'm using this validation plugin: ( http://www.position-absolute.com/articles/jquery-form-validator-because-form-validation-is-a-mess/ ) but when it
I'm currently trying to run the jQuery Validation plugin inside a jQuery dialog. The
I'm using the jQuery.Validation plugin for client side validation, and among other things I
Using the jQuery Validation plugin and AJAX, how can I validate the contents of
I'm using the jQuery Validation plugin and I've got a textbox with the class
Does jQuery validation plugin have some dependencies? For example, I saw blogposts that said

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.