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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T14:46:50+00:00 2026-05-25T14:46:50+00:00

Check if atleast one field is not empty in PHP is very equal to

  • 0

Check if atleast one field is not empty in PHP

is very equal to this question. This is just how to do it in javascript.

When you click on #submit it should check atleast one of these fields:

input[name=weight], input[name=size_1], input[name=size_2], input[name=size_3]

are filled, and not empty. If all of them are empty, it should alert(“Please fill one of the fields”)

Update: forgot to mention that if the fields are 0 it should not be counted as filled.

How can i do this? I tried copy over from php, but i get stuck on the foreach loop

  • 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-25T14:46:51+00:00Added an answer on May 25, 2026 at 2:46 pm

    You could do this very easily with the filter method:

    var filledFields = $('input[name=weight], input[name=size_1], input[name=size_2], input[name=size_3]')
        .filter(function() {
            return !!this.value && this.value !== '0'; // remove if value is empty or 0, keep otherwise
        });
    
    if (filledFields.length) {
        // at least one element has a value set
    } else {
        // no fields have values set
        alert("Please fill one of the fields")
    }
    

    What this does:

    1. Selects all the elements you want to check
    2. Runs the filter method: if you return true, the element will be kept; if you return false, it will be removed from the selection
      • !!this.value is true if the value is a non-empty string and otherwise is false
    3. We then check the length property of the selection. If it is not 0, at least one element has a non-empty value. If it is 0, they are all empty.

    See:

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

Sidebar

Related Questions

I am using this javascript code. and on button click I want that atleast
How to check whether an ASP.NET GridView has atleast one row, using JavaScript?
Update: Check out this follow-up question: Gem Update on Windows - is it broken?
I have this code I am checking wheather checkbox i checked or not.. $('#btnsubmit').click(function()
hI I WANT a script TO CHECK atleast one occurrence of |Viewed word is
This simple code checks if there is at lease one check box marked, When
Warning: very outdated question with an awful idea. Storing code, whether it be PHP,
I want to force the user to enter atleast one tag in tags field.
My HTML form contains many checkbox groups,I want to check if atleast one checkbox
I'm writing a custom validator that checks that at least one field has a

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.