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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T05:44:46+00:00 2026-06-03T05:44:46+00:00

I am trying to add validation to a form that is submitted by ajax,

  • 0

I am trying to add validation to a form that is submitted by ajax, and have it partially working.

Here’s the code that submits the form:

<script type="text/javascript">
$(document).ready(function(){$(".sendName").click(function(){
var Email=$("#Email").val();
var Name=$("#Name").val();
var ErrorType=$("input:radio[name=ErrorType]:checked").val();
var Univer=$("#Univer").val();
var ErrorMessage=$("#ErrorMessage").val();
$.post("report.php",{Email:Email,Name:Name,ErrorType:ErrorType,Univer:Univer,ErrorMessage:ErrorMessage},function(data){$("#loadName").html(data).effect('bounce', { times: 5, distance: 30 }, 300);
  });
 });
});
</script>

That code works perfectly.

I am also using the livevalidation plugin, and have it mostly working as well. The only problem I am having is calling the validation code from within the function that submits the form.

Normally the validation code is called like this:

 <form onsubmit="return validate(this)">

However, because the form is being submitted by ajax the current form tag is:

 <form onSubmit="return false;">

So what I need to be able to do is call the validate function from within the function that submits the form via ajax.

How would I do something like this? Both scripts are working fine on their own, it’s just this one last thing I need to figure out.

So I need to call the validate function when the ajax function is called, and if the form validates the script can complete the ajax request, and if the form does not validate it should not be submitted.

I did some searching and found a couple similar questions, but no solutions. Any help would be appreciated.

  • 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-03T05:44:47+00:00Added an answer on June 3, 2026 at 5:44 am

    The easier way to do this is to only cancel the submit if there is a validation error, otherwise let the submit happen normally.

    <form id="new-item" method="post" action="/i">
    

    Then in your javascript:

    $('#new-item').submit( function () {
    
      var valid = true;
    
      // do you validation logic
      valid = validate(this);
    
      // returning true will let the normal submit action happen
      // returning false will prevent the default action (i.e. the form will not be sumitted)
      return valid;
    
    });
    

    If you don’t want to use the standard submit functionality (though that is a best practice since it works when javascript is disabled) you would do a similar thing but just always return false.

    $('#new-item').submit( function () {
    
      var valid = true;
    
      // do you validation logic
      valid = validate(this);
    
      if (valid ) {
        // send your ajax post request here
      }
    
    
      // returning true will let the normal submit action happen
      // returning false will prevent the default action (i.e. the form will not be sumitted)
      return false;
    
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Im trying to add a Jquery validation script to a form plugin for wordpress.
I am trying to follow the code listed on https://github.com/alex/django-ajax-validation/blob/master/ajax_validation/views.py I have been able
I am trying to create form that contains another model in rails. I have
i am trying to add some realtime form validation for my registration page, however
I have an existing site that is working well with Authlogic login. I'm trying
I'm trying to add the jQuery Validation plugin to some websites and I'm running
I am trying to add a bit of security/validation logging to an ASP.NET MVC
Trying to setup some validation on the add to cart button for the dropdown
Trying to add a 'box' to a form at design time, I looked up
I was wondering how to go about form validation in rails. Specifically, here 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.