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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T23:07:03+00:00 2026-05-26T23:07:03+00:00

The script below is used to hide a paragraph until all text fields inside

  • 0

The script below is used to hide a paragraph until all text fields inside div.form have been filled out.

As it is now, in order to reveal the paragraphs I would have to fill out BOTH forms. What I want is for each form to act independently. In other words, if you filled out the three inputs in the first form, the paragraph in that first DIV would be revealed.

I can accomplish this by duplicating the code and adding more classes, but that is obviously less than ideal.

HTML

<div class="form one">  
    <input type="text" />
    <input type="text" />
    <input type="text" />
    <p style="display:none">All inputs in this DIV contain text</p> 
</div>

<div class="form two">  
    <input type="text" />
    <input type="text" />
    <input type="text" />
    <p style="display:none">All inputs in this DIV contain text</p> 
</div>

jQuery

$('.form input').keyup(function() {

    var empty = false;
    $('.form input').each(function() {
        if ($(this).val() == '') {
            empty = true;
        }
    });

    if (empty) {
        $('.form p').css('display', 'none');
    } else {
        $('.form p').css('display', 'block');
    }
});
  • 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-26T23:07:04+00:00Added an answer on May 26, 2026 at 11:07 pm

    You should simply select the inputs and the p from that .form:

    $('.form input').keyup(function() {
    
        var empty = false,
            $form = $(this).parent();
    
        $form.find('input').each(function() {
            if ($(this).val() == '') {
                empty = true;
                return false; // stops the loop
            }
        });
    
        if (empty) {
            $form.find('p').css('display', 'none');
        } else {
            $form.find('p').css('display', 'block');
        }
    });
    

    And here’s the fiddle: http://jsfiddle.net/tGBGK/

    P.S. You could further optimize this by caching the selectors.


    Alternatively, you could forego the loop, and just use an attribute selector:

    $('.form input').keyup(function() {
    
        var $form = $(this).parent(),
            empty = $form.find('input[value=]').length;
    
        if (empty) {
            $form.find('p').css('display', 'none');
        } else {
            $form.find('p').css('display', 'block');
        }
    });
    

    …and here’s the fiddle: http://jsfiddle.net/tGBGK/1/


    You can further shorten this, by using a ternary operator:

    $('.form input').keyup(function() {
    
        var $form = $(this).parent(),
            empty = $form.find('input[value=]').length;
    
        $form.find('p').css('display', empty ? 'none' : 'block');
    });
    

    …and finally, here’s the fiddle: http://jsfiddle.net/tGBGK/2/

    Thanks @JesseB.

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

Sidebar

Related Questions

The script below should open all the files inside the folder 'pruebaba' recursively but
I used the codes(html+php script) below to upload image file submit.html <html> <body> <form
I have tested the below script on a demo page which is not using
I have below script: $(document).ready(function () { $(#dpProject).change(function () { var idModel = $(this).val();
I've been trying the below script (within a larger app I'm working on) for
I wrote a jQuery script (below) and I used the (document).ready(function($)) function does it
I have a script I have used for quite a while that validates UK
I have the script below and on the website http://cacrochester.com , sometimes the contents
For example, I'm using the script below to check for empty fields : $('a.submit').click(function()
The script below will replace selected word in a textarea. But it only works

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.