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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T02:31:56+00:00 2026-05-18T02:31:56+00:00

i have a form with few fileds and a submit button… when i click

  • 0

i have a form with few fileds and a submit button… when i click on the submit button the form should validate and throw me an error of missing data but whats happening is that, it post the data and than validate the form

what should i do to validate the form and then post the form?

    <body>
     <form class="cmxform" id="commentForm" method="post" action="">
     <div class="subColumns paragraph">
            <div class="lefty">
                <div class="fontWeight7">  
                    <label for="first_name">
                    First Name:</label>
                    <input id="first_name" class="text required" maxlength="200" 
                        name="first_name"   />
                </div>
            </div>
            <div class="cdc-left">
                <div class="fontWeight7">
                    <label for="last_initial">
                    Last Initial:</label>
                    <input id="last_initial" class="required text" maxlength="200" 
                        name="last_initial"  />
                </div>
            </div>
        </div>
            <input id="btnRegister" name="btnRegister" class="submit" type="submit" value="Submit Your Answer" /> 
</form>




 <script type="text/javascript">

    $(document).ready(function () {

        $("#commentForm").validate(); 

        // validate the comment form when it is submitted  
        // validate signup form on keyup and submit
        $("#signupForm").validate({
            rules: {
                firstname: "required",
                lastname: "required",
                username: {
                    required: true,
                    minlength: 2
                },
                password: {
                    required: true,
                    minlength: 5
                },
                confirm_password: {
                    required: true,
                    minlength: 5,
                    equalTo: "#password"
                },
                email: {
                    required: true,
                    email: true
                },
                topic: {
                    required: "#newsletter:checked",
                    minlength: 2
                },
                agree: "required"
            },
            messages: {
                firstname: "Please enter your firstname",
                lastname: "Please enter your lastname",
                username: {
                    required: "Please enter a username",
                    minlength: "Your username must consist of at least 2 characters"
                },
                password: {
                    required: "Please provide a password",
                    minlength: "Your password must be at least 5 characters long"
                },
                confirm_password: {
                    required: "Please provide a password",
                    minlength: "Your password must be at least 5 characters long",
                    equalTo: "Please enter the same password as above"
                },
                email: "Please enter a valid email address",
                agree: "Please accept our policy"
            }
        }); 

        $("#commentForm").validate({
            submitHandler: PostData
        });  

    });

    function PostData() {
  debugger
    var _firstName = commentForm.first_name.value;// $('#first_name').value; //first_name.value;
    var _lastName = $('#last_initial').value; //last_initial.value;
    var _city = $('#city').value; //city.value;
    var _state = $('#state').value; //state.value;
    var _country = $('#country').value; //country.value;

     } 

</script>
  • 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-18T02:31:57+00:00Added an answer on May 18, 2026 at 2:31 am

    You’re hooking up the the click event on the button, which happens before the submit event on the form, instead use the submitHandler callback option for .validate(), like this:

    $("#commentForm").validate({
      submitHandler: PostData
    }); 
    

    …and remove this click handler completely:

    $('#btnRegister').click(function () {
      PostData();
    });
    

    The submitHandler only executes when the validation was successful, which would be what you want here.

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

Sidebar

Related Questions

So I have a Windows form with a few fields to accept data and
I have an online form that has a few fields with time data. I
I have form with few buttons and I want to know what button is
I have a form with a few fields. When you submit the form, the
I have problem with TinyMCE editor. I have form with few text fields and
I have a form with a table source, the form has a few fields
I have a form with a few input fields. When a user clicks on
I have a basic PHP form (a few fields and 2 checkboxes, I want
I have a simple html form with few fields in it. I wanted to
I have a long signup form and would like to hide a few fields

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.