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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T10:45:53+00:00 2026-05-30T10:45:53+00:00

Short What I want to do is following: At first, function validate() must check

  • 0

Short

What I want to do is following: At first, function validate() must check all inputs one by one: if they are not empty (or whitespaced) then move to if statement (for checking radio buttons) But if some of inputs empty then stop whole validate function and focus on empty input.

Here is result: http://jsfiddle.net/tt13/y53tv/4/

Just press ok button, you’ll see that it finished first function and fires if too. But I want to exit from whole validate() function in case there is empty field, not only from each() function

Detailed

JS

function validate() {
    $('.var_txt').each(function() {
        if ($.trim($(this).val()) == '') {
            $(this).focus();
            return false;
        }
    });

    if (!$(".answer:checked").val()) {
        alert("boom");
        return false;
    }
    return true;
}
$(document).ready(function() {
    $("#add_question").submit(function(e) {
        if (validate()) {
            alert("good");
        }
        e.preventDefault();
    })
});​

HTML Markup

 <form id="add_question" method="post" action=""> 
 <table>

                  <tr>

                    <td class="var_label">

                      <input class="answer" type="radio" name="answer" value="a" /> a)

                    </td>

                    <td>

                      <input type="text" class="var_txt" name="var_a" />

                    </td>

                  </tr>

                  <tr>

                    <td class="var_label">

                      <input class="answer" type="radio" name="answer" value="b" /> b)

                    </td>

                    <td>

                      <input type="text" class="var_txt" name="var_b" />

                    </td>

                  </tr>

                  <tr>

                    <td class="var_label">

                      <input class="answer" type="radio" name="answer" value="c" /> c)

                    </td>

                    <td>

                      <input type="text" class="var_txt" name="var_c" />

                    </td>

                  </tr>

                  <tr>

                    <td class="var_label">

                      <input class="answer" type="radio" name="answer" value="d" /> d)

                    </td>

                    <td>

                      <input type="text" class="var_txt" name="var_d" />

                    </td>

                  </tr>

                  <tr>

                    <td class="var_label">

                      <input class="answer" type="radio" name="answer" value="e" /> e)

                    </td>

                    <td>

                      <input type="text" class="var_txt" name="var_e" />

                    </td>

                  </tr>

                </table>
<input type="submit" name="submit" value="ok" />

</form>
  • 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-30T10:45:54+00:00Added an answer on May 30, 2026 at 10:45 am

    Add a flag that has to be false to continue.

    function validate() {
        var invalid = false;
        $('.var_txt').each(function() {
            if ($.trim($(this).val()) == '') {
                $(this).focus();
                invalid = true;
                return false;
            }
        });
        if (invalid) {
            return false;
        }
    
        if (!$(".answer:checked").val()) {
            alert("boom");
            return false;
        }
        return true;
    }
    $(document).ready(function() {
        $("#add_question").submit(function(e) {
            if (validate()) {
                alert("good");
            }
            e.preventDefault();
        })
    
    });​
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Following problem: I want to render a news stream of short messages based on
First of all, I want to say sorry for this very big question, but
first off a short explanation... the following two lines assure that once my website
In short: I want to monitor selected calls from an application to a DLL.
In short: I want to have two fullscreen views, where I can switch between
Short version: I want to trigger the Form_Load() event without making the form visible.
SHORT DESCRIPTION OF PROBLEM: I want to set the text of a searchbar without
Short version: assuming I don't want to keep the data for long, how do
I want to make a long list short by hiding some elements in long
I want to make a short URL service for 2 million assets but I

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.