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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T05:13:19+00:00 2026-06-06T05:13:19+00:00

TO CLARIFY I’VE GOT THE VALUES OF THE CHECKED CHECKBOXES. I NEED TO ORGANIZE

  • 0

TO CLARIFY I’VE GOT THE VALUES OF THE CHECKED CHECKBOXES. I NEED TO ORGANIZE THEM IN AN ARRAY SIMILAR TO THE PHP EXAMPLE GIVEN. THANKS

I’m trying to build an array of checked checkboxes to be sent over AJAX for processing by PHP. Originally I got the selected checkboxes by PHP but I’m having trouble converting this process to Javascript.

There are three different groups of checkboxes (‘first’, ‘second’, ‘third’) and for each of these groups there are 4 different checkboxes that can be checked.

The html of the checkboxes followings the same pattern up to value 4.

<input type="checkbox" name="first" class="selection first"  value="1"  />
<input type="checkbox" name="second" class="selection second" value="1"  />
<input type="checkbox" name="third" class="selection third" value="1"  />
<input type="checkbox" name="first" class="selection first"  value="2"  />
<input type="checkbox" name="second" class="selection second" value="2"  />
<input type="checkbox" name="third" class="selection third" value="2"  />

and so on….

The PHP code would return an array of the checked checkboxes like such.

$selections => array(
['first'] => array(
[0] => 1,
[1] => 3,
[2] => 4),
['second'] => array(
[0] => 2),
['third'] => array(
[0] => 1,
[1] => 4)
);

I’ve been trying and trying to replicate this in JavaScript but I keep getting errors such as cannot convert undefined to object and the likes. I loop the available positions to create arrays, then loop all the checkboxes and if checked, I get the value.

console.log() prints the position (‘first’, ‘second’ or ‘third’) and the number of the selection (1 – 4). That’s all I need, but how do I put this in an array similar to the PHP one?

function getSelections() {

var selections = new Array();

$('.position').each(function() {
    selections[$(this).attr('value')] = new Array;
});

$('.selection').each(function() {
    if( $(this).prop('checked') == true ) {
        position = $(this).attr('name');
        selection = $(this).attr('value');

        console.log(position + ' - ' + selection);
    }
});
return selections;

}

It’s to be sent to a PHP script as JSON and I need to decode it as an array like the PHP one.

  • 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-06T05:13:21+00:00Added an answer on June 6, 2026 at 5:13 am

    Nothing fancy needed…. change to this and view the posted arrays.

    <input type="checkbox" name="first[]" class="selection first"  value="1"  />
    <input type="checkbox" name="second[]" class="selection second" value="1"  />
    <input type="checkbox" name="third[]" class="selection third" value="1"  />
    <input type="checkbox" name="first[]" class="selection first"  value="2"  />
    <input type="checkbox" name="second[]" class="selection second" value="2"  />
    <input type="checkbox" name="third[]" class="selection third" value="2"  />
    

    Then serialize this as normal to submit via ajax instead.

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

Sidebar

Related Questions

To clarify: I'm not using the gettext php module /extension, reason being because I
Could anyone please clarify the difference between continuous and discrete attributes? Thanks.
To clarify the title, in a select statement, in the where clause, I need
Could anyone please clarify the defination of attribute? for example, in the following code,
need some help to clarify the concept. $sql = 'SELECT * FROM tbl_post LIMIT
To clarify my question, let's start off with an example program: #include <stdio.h> #pragma
To clarify my title, I need a way to determine that an object is
Firstly clarify that I checked a lot of posts before posting. Maybe I just
Let me first clarify that I'm not much familiar with PHP language, since I
To clarify, multiple students objects and all of them are getting the same value.

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.