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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T23:05:25+00:00 2026-06-02T23:05:25+00:00

OK, i have a couple of inputs. I have this code to validate them.

  • 0

OK, i have a couple of inputs. I have this code to validate them.

$("#form1").submit(function(){
    var isFormValid = true;

    $("#first_name").each(function(){
        if ($.trim($(this).val()).length == 0){
            isFormValid = false;
        }
    });

    if (!isFormValid) alert("Please Enter Your First Name");
    return isFormValid;
});

$("#form1").submit(function(){
    var isFormValid = true;

    $("#last_name").each(function(){
        if ($.trim($(this).val()).length == 0){
            isFormValid = false;
        }
    });

    if (!isFormValid) alert("Please Enter Your Last Name");
    return isFormValid;
});    

    $("#form1").submit(function(){
    var isFormValid = true;

    $("#dropdown").each(function(){
        if ($.trim($(this).val()).length == 0){
            isFormValid = false;
        }
    });

    if (!isFormValid) alert("Please Select Your Volunteer Choice");
    return isFormValid;
});

For some reason, i get a message after a message. What i was aiming for is that it only show me the next field that has not been field out, not all of them at the same time. If you have a question, please comment, it is hard to explain….do not down vote until you give me a chance to better explain.
​

  • 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-02T23:05:26+00:00Added an answer on June 2, 2026 at 11:05 pm

    Here is how to simplify your code, and make it work like intended.

    First, since you use the same method to validate all the fields, wrap that in a function instead of repeating the code:

    function isFieldEmpty(jQuerySelector) {
        return $.trim($(jQuerySelector).val()).length == 0
    }
    

    Second, use a single submit handler to check everything, and return false if any field does not pass validation:

    $("#form1").submit(function(){
    
        if(isFieldEmpty('#first_name')) {
            alert("Please Enter Your First Name");
            return false;
        }
    
        if(isFieldEmpty('#last_name')) {
            alert("Please Enter Your Last Name");
            return false;
        }
    
        if(isFieldEmpty('#dropdown')) {
            alert("Please Select Your Volunteer Choice");
            return false;
        }
    
        // Will return true only if all fields passed
        return true;
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have couple of questions about AS3 variables handling by AVM/compiler/scope .1. This code
I have written this ajax request for username checking... function check_username() { var username
I have a couple of tables which look like this Table 1 user_id |
I have a couple of unit test helper extension methods, such as, IsNotEmpty(this string
Can anybody help me out with this exception. I have tried couple of fixes
I have the following code for the jQuery validation plugin.... basically on submit, I
I have this javascript code that creates a slider: http://jsfiddle.net/samccone/ZMkkd/ Now, i want to
I have a couple of, what may end up being for this forum, overly-novice
I have a couple of forms on one page without a form name. Each
I have a couple of asp.net pages with TextBox controls on them. Some of

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.