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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T21:17:10+00:00 2026-06-04T21:17:10+00:00

I want to show a warning message if user does not complete entire form

  • 0

I want to show a warning message if user does not complete entire form but it seems not to work as I want. The jQuery .each method only collects data from the first input field. If I leave the first field empty it works correctly but if I fill only the first field and leave other fields empty it shows success which is wrong.

// send message on click
$("#submit").click(function() {

    // store values
    var data = $("#form").serialize();

    $(":input, textarea").each(function() {

        // if empty show warning
        if ( $(this).val() === "" ) {
            $(".message-fail").fadeIn(500);
        }

        // if not empty send message
        else if ( !$(this).val() ) {
                $.ajax({
                    type: "POST",
                    url: "mail.php",
                    data: data,
                    success: function() {
                        $(".message-sent").fadeIn(500);
                    }
                });
        }

    });

});
  • 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-04T21:17:11+00:00Added an answer on June 4, 2026 at 9:17 pm

    You can do following process:

    BUT I THINK YOU DON’T NEED AJAX FOR EVERY FIELD

    if ($.trim(this.value).length) { // if value exists
        $(".message-fail").fadeIn(500);
    } else { // if no value exists, here no need to elseif
        $.ajax({
            type: "POST",
            url: "mail.php",
            data: data,
            success: function() {
                $(".message-sent").fadeIn(500);
            }
        });
    }
    

    Explanation:

    $.trim(this.value) -> check for value exists

    or can also use (first one is better)

    $.trim($(this).val()).length -> checks for value exists

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

Sidebar

Related Questions

I want to have the following method not show a warning about using raw
want to show a error message as a result of a form action. For
I want to show a warning message to all of my logged in users
I want to show OrderDetails Count near the orders information in the grid but
I want to display jquery notifications, but at the moment it is fired onclick.
I want to show a warning when a certain file is opened, how can
Hey, my script seems to be getting this warning message whenever I run it.
I have a Warning Image(gif). I want to show this image only when Validation
I want show text in textbox in 2 colors, for example 1 line red
I want show annotation view (above one of my pin) after load map. For

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.