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

  • Home
  • SEARCH
  • 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 6001367
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T00:49:28+00:00 2026-05-23T00:49:28+00:00

I have the following code in jQuery that returns an array called responses. The

  • 0

I have the following code in jQuery that returns an array called responses. The array returned is based on the
position of the input elements.

var resp = $("input[id^= 'Answer_Response']");
responses: jQuery.map(resp, function (a) { return a.checked; })

<input id="Answer_Response[2]" name="Answer.Response[2]" type="checkbox" /> 
<input id="Answer_Response[0]" name="Answer.Response[0]" type="checkbox" />
<input id="Answer_Response[1]" name="Answer.Response[1]" type="checkbox" />
<input id="Answer_Response[4]" name="Answer.Response[4]" type="checkbox" />
<input id="Answer_Response[3]" name="Answer.Response[3]" type="checkbox" />

so When the inputs are:

 false    // for Answer.Response[2]
 true     // for Answer.Response[0]
 true     // for Answer.Response[1]
 false    // for Answer.Response[4]
 true     // for Answer.Response[3]

the responses array looks like false, true, true, false, true

what I need is for the array returned to be based on the id number for the elements. So for example I need an
array returned that looks like this: true, true, false, true, false

  true    // for Answer.Response[0]
  true    // for Answer.Response[1]
  false   // for Answer.Response[2]
  true    // for Answer.Response[3]
  false   // for Answer.Response[4]

Is there some way that I can do this in jQuery? please note that I can’t change the way that the responses are displayed. I’ve been asked to do this all in jQuery.

I hope someone can give some advice. I guess I just need some different way to do the mapping of resp but I’m not sure how I can do it.

  • 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-23T00:49:28+00:00Added an answer on May 23, 2026 at 12:49 am

    One way would be to use each:

    var resp = [ ];
    $("input[id^= 'Answer_Response']").each(function() {
        // Pull the number out of things like "Answer.Response[2]"
        var i   = parseInt(this.id.match(/\d+/)[0], 10);
        resp[i] = this.checked;
    });
    

    That should get the job done as long as the id attributes have exactly one substring that looks like a number (or at least the first match is the one you want) and there aren’t any gaps in your id attributes (or you’ll get some undefined entries in your resp array).

    And a simple demo: http://jsfiddle.net/ambiguous/hHS2K/

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

Sidebar

Related Questions

I have the following JQuery code that worked perfect in C#/Asp.net 2.0 to call
I have the following jquery code: jQuery(function(){ jQuery(select#rooms).change(function(){ var options = ''; jQuery.getJSON(/admin/selection.php,{id: jQuery(this).val(),
I have the following code, which works nicely: $('#register form .submit input').click(function(){ if(jQuery.trim($('#new-usr').val()) ==
So I have a problem with the following code. I have an array that
i have the following jquery code. basically i will have several overlapped divs and
I have the following JQuery code which does similar functionality like Stackoverflow where the
I have the following JQuery code: // When the document is ready, start firing
I have the following jQuery code which runs when I'm clicking an option in
I have the following code in a jQuery JavaScript document running on a page
I'm making a rating system, and I have the following jQuery code on my

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.