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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T00:41:24+00:00 2026-06-04T00:41:24+00:00

Here is the scenario. A user fills out a form. He forgets some required

  • 0

Here is the scenario.

A user fills out a form. He forgets some required info. My validation code indicates to the user the missing field is required. He fills out the form fully and submits. Presto it works.

Now, the user manually deletes the required field and hits submit again. Presto it works (IT SHOUDLNT). How can I get my validation to work a second time around to prevent empty fields from being submitted? Here is my code. It only works on 1 iteration of a form submit. All subsequent submits ignore my validation.

Thank you…

//Validation  
$('#CommentsForm').validate({
    rules: {
        Author: "required",
        Message: "required"
    },
    messages: {
        Author: "Author is required.",
        Message: "Comment is required."
    },
    errorContainer: "#CommentsErrorBox",
    errorLabelContainer: "#CommentsErrorBox ul",
    wrapper: "li"
});

//User Clicked Submit Button
$('#CommentsForm').live('submit', function (e) {
    e.preventDefault(); //Prevent Browser from getting new url

    //Create JSON object
    var jsonCommentData = {
        ID: $('#HiddenID').val(),
        Author: $('#Author').val(),
        Message: $('#Message').val()
    }

    //Add the comment.
    $.ajax({
        url: '/Home/_CommentsAdd',
        type: 'POST',
        data: JSON.stringify(jsonCommentData),
        dataType: 'html',
        contentType: 'application/json',

        //The request was a success. Repopulate the div with new result set.
        success: function (data) {
            $('#AjaxComments').html(data);
            $('abbr.timeago').timeago(); //update the timestamp with timeago

            //Change colors of message.                
            if ($('#CommentStatus').html() == "Your Comment Has Been Added!") {
                $('#CommentStatus').css('color', 'GREEN');
            }
        },
        error: function (data) {
            alert('Fail');
        }
    });
});

Here is my Partial view: _Comments

@model DH.ViewModels.CommentsViewModel

<div id="AjaxComments">
@{
    <input type="hidden" id="HiddenPageNumber" value="@Model.PageNumber.ToString()" />
    <input type="hidden" id="HiddenPageCount" value="@Model.PageCount.ToString()" />

    //No Comments Yet
    if (Model.CommentStatus.Length > 0)
    {
            <div id="CommentStatus">@Model.CommentStatus</div>
    }

    foreach (var item in Model.Comment)
    {   
        <div class="CommentContainer">
            <div class="RateComment">
                <img src="/content/images/icons/Thumbs-Up-16x16.png" alt="Thumbs Up" title="Uprate Comment" style="margin-top: 10px;" />
                <div class="CommentRating">8</div>
                <img src="/content/images/icons/Thumbs-Down-16x16.png" alt="Thumbs Down" title="Downrate Comment" style="margin-top: 5px;" />
            </div>
            <div class="CommentHeader">
                <div class="CommentAuthor">@item.Author</div>
                <div class="MessageDate">
                    <img src="/content/images/icons/Clock-16x16.png" width="16" height="16" alt="Comment Time" style="vertical-align: middle; padding-bottom: 2px;" />
                    <abbr class="timeago" title="@item.MessageDate" style="border-bottom-width: 0;">@item.MessageDate</abbr>
                </div>
            </div>
            <div class="CommentMessage">@item.Message</div>
            <div style="clear: both;"></div>
        </div>
    }
}

<div id="Pagination">
@{ 
    //Setting up Increments of 10 Pagination links
    int StartPage;
    int EndPage;
    int PageNumber = Model.PageNumber;
    int PageCount = Model.PageCount;

    if (PageCount < 10) {
        StartPage = 1;
        EndPage = PageCount;
    }
    else {
        if (PageNumber < 10) {
            StartPage = 1;
            EndPage = 10;
        }
        else {
            StartPage = PageNumber - 5;
            EndPage = PageNumber + 4;
            if (EndPage > PageCount) {
                EndPage = PageCount;
                StartPage = EndPage - 9;
            }
        }
    }

    //Display "Page of" if there are comments.
    if (@Model.PageCount > 0)
    {
        <div id="PageOf">Page @Model.PageNumber of @Model.PageCount</div>
    }

    //Set up First and Prev arrow links
    if (Model.PageNumber > 1) {
        <a class="PaginationLink" title="Prev" href="">< Prev</a>
    }

    //Loop through and create the page #'s.
    for (var PageCounter = StartPage; PageCounter <= EndPage; PageCounter++) {
        //Display the Page # in a Black Box
        if (PageCounter == PageNumber) {
            <span class="CurrentPage">@PageNumber</span>
        }
        //Create the Page # Links.
        else {
            <a class="PaginationLink" title="@PageCounter" href="">@PageCounter</a>
        }
    }

    //Set up Next and Last arrow links
    if (Model.PageNumber < Model.PageCount) {
        <a class="PaginationLink" title="Next" href="">Next ></a>
    }
} 
</div>

<div id="CommentsFormContainer">
    <form id="CommentsForm" action="">
    <div id="CommentsErrorBox"><ul></ul></div>
    <fieldset id="CommentsFormFieldset">
        <legend id="CommentsFormLegend" align="center">Add a Comment</legend>
        <label for="Author" class="LabelAuthorMessage">Author:&nbsp;</label><input type="text" id="Author" name="Author" size="30" class="CommentInputs" />
        <label for="Message" class="LabelAuthorMessage">Comment:&nbsp;</label><textarea id="Message" name="Message" cols="35" rows="5" class="CommentInputs"></textarea>
        <input type="text" id="CharCount" value="0" readonly="readonly" />&nbsp;&nbsp;
        <label for="CharCount" id="LabelCharCount">* Max 200 Characters</label>
        <input type="submit" id="SubmitComment" value="Submit" name="SubmitComment" style="float: left; margin-left: 50px;" />
    </fieldset>
    </form>
</div>

  • 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-04T00:41:27+00:00Added an answer on June 4, 2026 at 12:41 am

    Your problem is totally with your implementation.

    The following occurs when the page loads which makes your form work sucessfully on the first submit…

    var validator = form.validate({
        rules: {
            Author: "required",
    
            etc....
    

    Then, because you’ve enclosed it again within a submit handler, it’s reinitialized here…

    form.live('submit', function (e) {
        e.preventDefault(); //Prevent Browser from getting new url
    
        $(this).validate();
    

    … which breaks it for the next submit.

    All you need to do is initialize it once (including all the options) and not inside a submit handler…

    $('#CommentsForm').validate({
        rules: {
            Author: "required",
    
            etc....
    

    Refer to the source code of these official demos.


    EDIT:

    Again, you do not need a submit handler as it’s interfering with your form submission.

    In other words, your validation is working fine but when you hit “submit”, your external submit handler function takes over completely so it’s no wonder that validation then starts failing.

    As I mentioned in my original comments, the Validation plugin has a submit handler built in to handle everything including your ajax.

    Remove all this completely…

    form.live('submit', function (e) { ....
    

    Then inside your validate() function, you’d simply add a submit handler as per the plugin documentation listed as the second option…

    $('#CommentsForm').validate({
        rules: {
            Author: "required",
    
            /// etc....
    
        },
    
        submitHandler: function(form) {
    
            /// put all your ajax and such in here
    
        }
    
     });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Here is my scenario. User fills out this large page which is dynamically created
Okay so here's the scenario: User is presented with form that contains file inputs.
here is the scenario 1: user starts to type some word, autocomplete engine shows
Here I am explaining the scenario - The user, after providing a service has
Here's the scenario: if this is a user's first time logging into my web
Here's my scenario: <!-- Normal Control --> <div class=required> <label for=address1>Address line 1</label> <input
Here is the scenario: I have a visual that displays some data The data
Here is the scenario: There is a index.php file in root folder some files
i've got a site, which has a login system. here's my scenario: user is
Here's my scenario. I call jqModal using its ajax functionality that displays a form

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.