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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T10:35:50+00:00 2026-05-27T10:35:50+00:00

This has got me stumped. I can easily get the value of a multiselect

  • 0

This has got me stumped. I can easily get the value of a multiselect as an array, and pass it to an ajax request:

<select id="countries" class="multiselect" multiple="multiple" name="countries[]">
  <option value="AFG">Afghanistan</option>
  <etc>
...
$countries_input = $("#countries");
var countries = $countries_input.val();
$.ajax({
  data: {
    country : countries,
    ...
  },
  ...
});

but I can’t find any equivalent way to get the values of a checkbox with multiple selections. The obvious stuff doesn’t work:

<input type="checkbox" name="check[]" value="foo1"/>foo1<br/>
<input type="checkbox" name="check[]" value="foo2"/>foo2<br/>
...
var bar = $('input:checkbox[name=check]').val();         // undefined
var bar = $('input:checkbox[name=check[]]').val();       // also undefined
var bar = $('input:checkbox[name=check]:checked').val(); // also undefined

Any ideas? Thanks.

  • 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-27T10:35:51+00:00Added an answer on May 27, 2026 at 10:35 am

    There’s no built-in jQuery function for that. You have to do it yourself. You can do it easily enough with a simple loop:

    var vals = []
    $('input:checkbox[name="check[]"]').each(function() {
        vals.push(this.value);
    });
    

    Or if you only want the checked ones:

    var vals = []
    $('input:checkbox[name="check[]"]').each(function() {
        if (this.checked) {
            vals.push(this.value);
        }
    });
    

    Or you can use map and get:

    var vals = $('input:checkbox[name="check[]"]').map(function() {
        return this.value;
    }).get();
    

    Or if you only want the checked ones:

    var vals = $('input:checkbox[name="check[]"]').map(function() {
        return this.checked ? this.value : undefined;
    }).get();
    

    Side note 1: jQuery requires the value in an attribute value selector (the kind above) always be in quotes, although as of this writing despite documenting that it’s still lax about it. It’s a jQuery thing, but in this case you’d need it for CSS as well (CSS2 Reference | CSS3 Reference) because your value includes [], which aren’t valid for values without quotes in CSS. (In CSS, without quotes the values must be identifiers.)


    Side note 2: Note I used this.value in the iterator functions above to get the value of the input, rather than $(this).val(). It’s pretty much just a style thing, neither is better than the other from all perspectives. this.value is more direct and if you know the DOM at all (and every web programmer should), it’s perfectly clear. But of course, while perfectly reliable cross-browser with checkboxes and most other input elements, it isn’t reliable cross-browser with some other form fields (select boxes, for instance). $(this).val() is more idiomatic in a jQuery-intensive application, and you don’t have to worry about whether this is an input or a select. Yes, it adds overhead, but if you don’t have thousands of them, it’s not like it’s going to matter.

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

Sidebar

Related Questions

This has got me completely stumped: print_r($json); echo json_encode($json); output: Array ( [query] =>
This has got me stumped, I've tried lots of different things, but I can't
I'm admittedly a straight-C newbie, but this has got me stumped. I'm working on
This one has me stumped. I've got a java.sql.ResultSet and I'm pulling string values
Ok, this has got to be a super simple problem. I just can't seem
This one has got me stumped. I'm deploying a Rails 3 app to Slicehost
This one has got me stumped. I am currently rendering a form using ASP
I've got a problem with ODBC that has me stumped, and I can't find
This has got to be something I just missed, but how do I add
This has got to be something simple: I set up a frames page with

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.