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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T03:37:06+00:00 2026-05-14T03:37:06+00:00

I’m confused regarding each() and .each()… I think I need to use both, but

  • 0

I’m confused regarding each() and .each()… I think I need to use both, but I’m not sure how…

Basically, I have a series of checkboxes and when they’re checked, I want to get the id of the closest table row and add it to an array that I can then serialize and pass to a function.

So, the html looks like this:

<tr id="t1"><td><input type="checkbox" name="did[]" value="232" class="bd" /></td></tr>
<tr id="t2"><td><input type="checkbox" name="did[]" value="234" class="bd" /></td></tr>
<tr id="t3"><td><input type="checkbox" name="did[]" value="676" class="bd" /></td></tr>
<tr><td><button id="tsid" name="tsid" type="button">Send</button></td></tr>

And, when (and if) the checkbox is selected, I want to get the closest tr id and store it in an array:

var trids = []

And then serialize the input data and the trids array…

So far, I only have this:

$('#tsid').click(function() {

  //meant to get the values of the selected checkboxes
  var myData = $('input[name=did[]]').serialize();

  //meant to find and store the closest tr ids in an array... 
  $('.bd').each(function() {
    var trids = $(this).closest("tr").get(0);  //and now I'm lost... 
  });

}
  • 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-14T03:37:06+00:00Added an answer on May 14, 2026 at 3:37 am

    It should just be:

    $('.bd:checked').each(function() {
       trids.push($(this).closest("tr").attr('id')); // instead of var trids = ....
    });
    

    $('.bd:checked') selects only the checked checkboxes.
    closest('tr') gets the parent tr as you already did it correctly. attr('id') gets the id of this tr. There is no need in get(0) as closest() already selects just one element.
    Then this value is added to the array trids by using the push() method on the array.

    Update:
    jQuery’s .searialize() function generates a string out of the values of form elements, e.g.:

    field1=value1&field2=value2&...
    

    I don’t think it works on arrays though. The only solution I know would be generate the string for the array by yourself:

    var myData = $('input[name=did[]]').serialize();
    
    for(var i = 0; i < trids.length; i++) {
        myData += '&trid[]=' + trids[i]; or // '&trid%5B%5D=' have it encoded.
    }
    

    This would append the array values to the serialized string.
    But I guess there is a better solution for this.

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

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I'm not entirely sure how I managed to jack this up. http://pretty-senshi.com If you
I have a French site that I want to parse, but am running into
This could be a duplicate question, but I have no idea what search terms
I need a function that will clean a strings' special characters. I do NOT
I have thousands of HTML files to process using Groovy/Java and I need to
I need to clean up various Word 'smart' characters in user input, including but
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and

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.