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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T14:32:47+00:00 2026-06-06T14:32:47+00:00

I am working on an assessment system. There are many ‘questionItem’ blocks on the

  • 0

I am working on an assessment system. There are many ‘questionItem’ blocks on the page. the goal is to identify the ones where the answers[2].SetAnswer or answers[2].Answer are set to either an empty string or ? and high light the title (item). When the user changes the question, remove the highlight.

It works, I am simply looking for how I might be able to improve it. Here is one block:

$<div class="questionItem">
    <input data-val="true" data-val-number="The field MappingId must be a number." data-val-required="The MappingId field is required." id="answers_2__MappingId" name="answers[2].MappingId" type="hidden" value="24" />
    <input id="answers_2__Item" name="answers[2].Item" type="hidden" value="B0300" />
    <input id="answers_2__OldAnswer" name="answers[2].OldAnswer" type="hidden" value="^" />
    <input id="answers_2__SetAnswer" name="answers[2].SetAnswer" type="hidden" value="^" />
    <h3 class="item">B0300</h3>
    Hearing aid<br/>
    <select class="hyperSwap" id="answers_2__Answer" name="answers[2].Answer">
        <option selected="selected" value="?">(select item)</option>
        <option value="0">(0) No</option>
        <option value="1">(1) Yes</option>
        <option value="-">(-) Not assessed</option>
    </select>
</div>

<div class="questionItem">
    <input data-val="true" data-val-number="The field MappingId must be a number." data-val-required="The MappingId field is required." id="answers_11__MappingId" name="answers[11].MappingId" type="hidden" value="228" />
    <input id="answers_11__Item" name="answers[11].Item" type="hidden" value="C0900A" />
    <input id="answers_11__OldAnswer" name="answers[11].OldAnswer" type="hidden" value="0" />
    <input id="answers_11__SetAnswer" name="answers[11].SetAnswer" type="hidden" value="?" />
    <h3 class="item">C0900A</h3>
    Staff asmt mental status: recall current season <br/>
    <div class="questionCheckbox"><input id="C0900A_0" name="answers[11].Answer" type="radio" value="0" /> (0) Not checked (No)</div>
    <div class="questionCheckbox"><input id="C0900A_1" name="answers[11].Answer" type="radio" value="1" /> (1) Checked (Yes)</div>
    <div class="questionCheckbox"><input id="C0900A_-" name="answers[11].Answer" type="radio" value="-" /> (-) Not assessed</div>
</div>

And here is the jQuery code I have came up with:

$function highlightUnanswered() {
    var coll = $(".questionItem").filter(function () {
        return $(this).find(":input").filter(function () {
            return (/^answers\[\d+\]\.SetAnswer$/.test(this.name) && this.value == "?") ||
                           ((/^answers\[\d+\]\.Answer$/.test(this.name) && this.value == "?") &&
                            (/^answers\[\d+\]\.Answer$/.test(this.name) && this.value == ""));
        }).length > 0;
    });

    coll.find(".item").addClass("unanswered");
    coll.find(":input").change(function (e) { $(this).parent().find(".item").removeClass("unanswered"); });
}

There are two questions:

Q1: the very last line, if I am not mistaken the handler is being added to ALL the inputs, including the hidden ones. How to I just wire it up to the answers[#].Answer input?

Q2: Someone on this form gave me the first query that comes up with the initial collection for a different feature. I understand what it is doing, but I don’t understand how: What is up with /^answers[\d+].Answer$/.test(this.name)? Why is there a .length() > 0 at the end?

  • 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-06T14:32:48+00:00Added an answer on June 6, 2026 at 2:32 pm

    Q1:

    coll.find(":input").filter(function(){
      return (/^answers\[\d+\]\.Answer$/.test(this.name);
    }).addClass('unanswered');
    

    Q2:

    http://api.jquery.com/filter/ says: “For each element, if the function returns true (or a “truthy” value)”, so the filter function could simply return .length: 0 is falsy, other numbers are truthy.

    /^answers[\d+].Answer$/ is a regular expression:

    https://developer.mozilla.org/en/JavaScript/Guide/Regular_Expressions

    .test(this.name) checks if the currently processed input’s name matches the required format.

    https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/RegExp/test

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

Sidebar

Related Questions

Working on a page with multiple sections. at the very top there is a
I am working for a K-12 school and I am developing a gradebook system.
Working on THIS Page: newsite.702wedding.com/live/ Can't find where to remove the arrows at the
Working on a somewhat complex page for configuring customers at work. The setup is
I'm new to the Java scene but currently working on an assigned assessment. I'm
Working on a bunch of forms at the moment and I'm finding that I
Working on a website that has Employee and Branch entities, using a database table
Working on a rather small, and simple layout, I decided to use Meyer's CSS
Working on an irc client in Adobe AIR in JavaScript, and thinking about logging.
Working with Linq2Sql as a driver for a Wcf Service. Lets go bottom up....

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.