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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T04:16:43+00:00 2026-05-19T04:16:43+00:00

I have a form in my admin panel and am having a bit of

  • 0

I have a form in my admin panel and am having a bit of trouble with my references in jQuery.

The form code looks like this:

<div class="full-width">
    <label for="file_name-644" >File Name</label> 
    <span class="relative"><input type="text" name="file_name-644" id="file_name-644" class="full-width" disabled="disabled" value="pic.jpg"/><span ></span></span>
</div>
<div class="full-width">
    <label for="name-644" class="required">Name</label> 
    <span class="relative"><input type="text" name="name-644" id="name" value="" class="full-width name"/><span ></span></span>
</div>

now, as this form can have multiple entries processed at once, the numbers will change on the references (so from 644 to 108 for example). This is created with a php loop.

In jquery i’m using an .each() loop to check that the values are filled. Right now, all I need for validation is non-empty fields for the name. Currently, it looks like this:

$('.name').each(function(index) {
    if(!$(this).val()){ctr++;}else{error++;}
});

The variables ctr and error are counters that I later use to point out errors or how many entries are ready to be processed.

What I want to add to this is a change to the label for just the entries that are empty so that these stand out. I know I can change all of them with
$('.required').css({'color': '#AB1414'});
but how can I do this in the .each() loop above and just for the empty values?

Thanks in advance!

  • 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-19T04:16:44+00:00Added an answer on May 19, 2026 at 4:16 am

    To use the .each() loop in your code, you could do the following. Note that it uses jQuery.trim()(docs) to consider values with only white space to be empty as well.

    Using prev()(docs) it also gets the previous <label> of its parent()(docs) , but only if it has the required class. Then in the if(), it checks the length(docs) property of the <label> object to see if there indeed was a required label.

    $('.name').each(function(index) {
        var $th = $(this);
        if( $th.parent().prev('.required').length && !$.trim( $th.val() ) ){ctr++;}else{error++;}
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a form like this: <form name=mine> <input type=text name=one> <input type=text name=two>
I have a namespaced controller for some admin functionality. My create form does not
I have created an admin panel for a client in PHP, which requires a
I have a problem in my project. There is an admin panel in my
I have a form where an admin will upload three pictures with different dimensions
This is what I'm trying to do. Have one main form with all the
I have a form for an object called AccountImport . This form lives in
I have form area in my view. If I click button A , I
I have form that displays several keywords (standard set of choice lists that changes
I have a form in C# that has a button that, when clicked, 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.