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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T17:17:00+00:00 2026-06-07T17:17:00+00:00

validation works fine with the form and validation plugin as static form. i need

  • 0

validation works fine with the form and validation plugin as static form. i need to insert the form into the page and then have it validate – not working for me.

  $(document).ready(function(){
   var validator = $("#loginForm").validate({
       // rules for field names
       rules: {
            cname: "required", 
            cpass: "required"
    },
    // inline error messages for fields above
    messages: {

            cname: "required", 
            cpass: "required"
    }
}); // for validating the form

$("#loginForm").validate({
  submitHandler: function(form) { //Only runs when valid
      form.submit();
  }
});   

  var htmlStr = '<form class="cmxform" id="loginForm" method="get" action="https://www.myURL.com/login.php"><p><label for="cname">Name</label><em>*</em><input id="cname" name="name" size="25" class="required" minlength="2" /></p><p><label for="cpass">Password</label><em>*</em><input type="password" id="cpass" name="pass" size="25" class="required" minlength="2" /></p><input id="mySubmit" class="submit" type="submit" value="Submit"/></form>';

  function createForm(){
  // fires with body onload
  $("#login-container").html(htmlStr);
     };
  • 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-06-07T17:17:02+00:00Added an answer on June 7, 2026 at 5:17 pm

    Move your validation code to right after you add the html to the page. Since $("#loginForm") likely doesn’t exist in your document.ready function, nothing in the validate area ever gets run. You probably want your code to look like this:

    function createForm(){
      // fires with body onload
      $("#login-container").html(htmlStr);
    
      var validator = $("#loginForm").validate({
         // rules for field names
         rules: {
                cname: "required", 
                cpass: "required"
        },
        // inline error messages for fields above
        messages: {
                cname: "required", 
                cpass: "required"
        }
      });  
    }
    

    Other problems you had – no need to submit the form manually in submitHandler – the validator will do that for you if the form is valid. Also, with the way you’ve set up your messages object, the actual error message will be the word “required”. Not sure if that’s what you want or not…

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

Sidebar

Related Questions

i have a jquery form validation in the master page and it works fine
I have written a few jquery functions for form validation. It works fine but
The form validation works fine, so if u leave the email input blank and
I have a form that calls on two separate models. My validation works correctly
I'm using the jQuery validation plugin from bassistance.de. It works fine. From <head> :
I was writing a simple login form, everything works fine (validation etc.) but I
I've got a wpf form where validation works fine for single-field validation. I've got
I'm working on a web form which works fine as long as it posts
I have a form which I am validating through the jQuery Validate plugin. Everything
I have a problem with the scoped uniqueness validation in Rails. It works fine

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.