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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T10:51:33+00:00 2026-05-24T10:51:33+00:00

I am trying to validate a form. The form is dynamically generated and added

  • 0

I am trying to validate a form. The form is dynamically generated and added to div on the page. When submitting the form I want the validation to be performed at once. What happens now is that the first time I submit the form is posted without being validated. The second time I hit submit it’s validate.

Here is my script:

$("#registerform").live("submit", function(e){
                        //Prevent the form from submitting normally
                        e.preventDefault();
                       $("#registerform").validate({ 
                            rules: { 
                              firstname: "required",// simple rule, converted to {required:true} 
                              surname: "required",
                              //phonenumber: "required",
                              address: "required",
                             // address2: "required",
                              zipcode: "required",
                              username_ID: "required",
                              city: "required",
                              companyname: "required",
                              email: {// compound rule 
                              required: true, 
                              email: true 
                            }              
                            }, 
                            messages: { 
                              firstname: "Förnamn saknas" ,
                              surname: "Efternamn saknas",
                              address: "Adress saknas",
                             // address2: "required",
                              zipcode: "Postkod saknas",
                              username_ID: "Användarnamn saknas",
                              city: "Ort saknas",
                              companyname: "Företagsnamn saknas",
                              email: "Korrekt emailadress saknas"                             
                            } 
                          }); 
                        //alert("e");
                    $.post("registeraccount.php",$(this).serialize(),function(msg){
                    //alert the response from the server
                    //alert(msg);
            });
    });

My form:

<form id='registerform' action='registeraccount.php' method='post'> 
            Ägare av konto</br>
            * Förnamn: <input type='text' name='firstname' /> <br/>
            * Efternamn: <input type='text' name='surname' /> <br/>
            * Email: <input type='text' name='email' /> <br/>
            * Telefon: <input type='text' name='phonenumber' /> <br/>
            Företagsinformation: </br>
            * Adress: <input type='text' name='address' /> <br/>
            Adress: <input type='text' name='address2' /> <br/>
            * Postnummer: <input type='text' name='zipcode' /> <br/>
            * Ort: <input type='text' name='city' /> <br/>

            <br/>
            Kontoinformation</br> 
            <div id='username_message'></div>
            * Användarnamn: <input id='username_ID' type='text' name='username' />

            <br/>
            Företagsinformation<br/>
            * Företagsnamn (som kunden kommer se det): <input type='text' name='companyname' /> <br/>
            Organisationsnummer: <input type='text' name='organisationnumber' /><br/>
            <input id='submitaccountregistration' type='submit' value='Submit Comment' /> 
        </form>

How come it’s not triggered on the first submit and how can I get the validation to be performed the first time I hit submit?

  • 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-24T10:51:33+00:00Added an answer on May 24, 2026 at 10:51 am

    At first submit event you are not validating form, but just attaching validator plugin to it. At second submit you are validating it and attaching validation again.

    Just define function which adds your validation (function attachValidate(form) { $(form).validate… }) and run this function when form is generated/loaded.

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

Sidebar

Related Questions

I'm trying to validate a form using the validate plugin for jquery. I want
I am trying to validate the WPF form against an object. The validation fires
I'm trying to user jQuery Validation plugin to validate a signup form, but I
I am trying to validate the form input but my validation is not working.
I'm trying to validate a basic form, can i not use the standard validation
I am currently trying to validate a form server side, the way it works
Hey there, I'm trying to validate a form with Zend_Validate and Zend_Form. My element:
I was trying to validate an XML signature. The validation according to this tutorial
I'm trying to add a validation rule to multiple textboxes dynamically. Here's the js:
I'm trying to dynamically add a validation rule to some dynamic controls: $(input[id*=Hours]).rules(add, required);

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.