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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T23:10:09+00:00 2026-05-27T23:10:09+00:00

This is not a problem, I just ask for the easiest way to implement

  • 0

This is not a problem, I just ask for the easiest way to implement this.

What I have.

In HTML: list of checkboxes.

<input type="checkbox" value="1" />
<input type="checkbox" value="2" />
<input type="checkbox" value="3" />
<input type="checkbox" value="4" />

In JavaScript — array of several values: var aValues = [1, 3]; And I need fetch all checkboxes from DOM with values specified in aValues.

How did I do this:

var aoNodes = document.querySelectorAll('input[value="1"], input[value="3"]');

But maybe anybody know easier (shorter) way to build the query, something like: input[value="1"|"3"] or input[value="1", "3"].

Both examples above are incorrect, but I gave them just to be more clear with you.

UPDATE

More things to clarify my question:

  • jQuery can’t be used in my case
  • We use ExtJS in our project.
  • 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-27T23:10:09+00:00Added an answer on May 27, 2026 at 11:10 pm

    Your querySelectorAll('input[value="1"], input[value="3"]') is probably the briefest, even CSS3 doesn’t have an attribute selector for “any of these values”. (Neither does jQuery.) You can build the big selector from aValues fairly easily using Array#join:

    var selector = 'input[type="checkbox"][value="' +
                   aValues.join('"], input[type="checkbox"][value="') +
                   '"]');
    var matches = querySelectorAll(selector);
    

    Fairly concise though sadly repeats bits and pieces. You could use a reusable function:

    function niftyJoin(array, prefix, delim, suffix) {
      return prefix + array.join(suffix + delim + prefix) + suffix;
    }
    

    Then:

    var matches = querySelectorAll(niftyJoin(aValues, 'input[type="checkbox"][value="', ',', '"]'));
    

    If you don’t like the join approach, you could get all relevant input elements and then filter out the ones whose values are not in the array:

    var matches, inputs, index, input;
    matches = [];
    inputs = querySelectorAll('input[type="checkbox"]'); // Or perhaps more targeted
    for (index = 0; index < inputs.length; ++index) {
        input = inputs[index];
        if (aValues.indexOf(parseInt(input.value, 10)) !== -1) {
            matches.push(input);
        }
    }
    

    That might be slower than building the big selector for querySelectorAll since you’re filtering in the JavaScript layer rather than the browser’s selector engine, but unless you’re doing this repeatedly in a tight loop, it’s not likely to matter. Also, note that I’ve relied on Array#indexOf, which isn’t supported by quite as many browsers as querySelectorAll (IE8 has the latter, for instance, but not the former).

    Speaking of which: I’m guessing you know that not all browsers support querySelectorAll yet, although wow it’s getting close, looks like nearly everything but IE6 and IE7. I assume if you’re using it, you know that your target environment will have it.


    For the jQuery folks: That filtering gets (much) more concise using jQuery:

    var matches = $('input[type="checkbox"]').filter(function() {
        return $.inArray(parseInt(this.value, 10), aValues);
    });
    

    Nice and concise. Again, possibly a bit slower than doing it all in querySelectorAll, and again unlikely to matter.


    Update: You’ve said you’re using ExtJS on this project. According to the DomQuery docs, it doesn’t offer a selector that does what you want either. It does offer filter which could be useful if you want to do the filter-after-the-fact approach, but I frankly think the join approach listed at the very top is going to be the most concise and best performing.

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

Sidebar

Related Questions

This is not really a question because I just solved the problem, but I
This just won't work. The problem is that I do not know enough to
I'm trying to solve this problem, its not a homework question, its just code
I knew this was a problem I would run into and I'm just not
This is not a technical problem, but very annoying. Does anyone know how to
In xp 32bit this line compiles with not problem however in vista 64bit this
This problem is not readily reproducible in a simple example here but was wondering
This is not really a programming question, more of an algorithmic one. The problem:
I had a leaking handle problem (Not enough quota available to process this command.)
excuse me in advance if this is not the right title for the problem

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.