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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T00:26:39+00:00 2026-05-15T00:26:39+00:00

Say I have this <table border=1 id=tbl> <tr> <td><input type=checkbox name=vehicle value=Bike /></td> <td>row

  • 0

Say I have this

<table border="1" id="tbl">
<tr>
<td><input type="checkbox" name="vehicle" value="Bike" /></td>
<td>row 1, cell 1</td>
<td>row 1, cell 2</td>
</tr>
<tr>
<td><input type="checkbox" name="vehicle" value="Bike" /></td>
<td>row 2, cell 1</td>
<td>row 2, cell 2</td>
</tr>
</table> 

Now I want to get the row that is checked, then the cell values of that checked row. So I would do this

 var cells = $('#tbl :checked').parents('tr').children('td');

So lets assume only one checkbox can be checked(so no jQuery foreach loop).

So now say I wanted to get the 2nd table cells value I would just go

var secondCell = $(cells[1]).html();

The thing with this though it makes the code so brittle. Like what if I put another table cell after after the checkbox one?

<table border="1" id="tbl">
<tr>
<td><input type="checkbox" name="vehicle" value="Bike" /></td>
   <td> I am new </td>
  <td>row 1, cell 1</td>
  <td>row 1, cell 2</td>
</tr>
<tr>
<td><input type="checkbox" name="vehicle" value="Bike" /></td>
   <td> I am new </td>
  <td>row 2, cell 1</td>
  <td>row 2, cell 2</td>
</tr>
</table> 

So now I have to go through my code and change this

var secondCell = $(cells[1]).html();

to this

var thirdCell = $(cells[2]).html();

Since now I am actually after the 3rd cell and not the 2nd cell anymore.

So is there a better way?

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-15T00:26:40+00:00Added an answer on May 15, 2026 at 12:26 am

    Give the tds of interest a classname so that you can select them using the classname selector.

    <tr>
        <td><input type="checkbox" name="vehicle" value="Bike" /></td>
        <td> I am new </td>
        <td class="cell1">row 1, cell 1</td>
        <td class="cell2">row 1, cell 2</td>
    </tr>
    

    with

    var row = $('#tbl :checked').parents('tr');
    var cell1 = $('.cell1', row);
    var cell2 = $('.cell2', row);
    

    You would probably also rather use text() to get its contents. The html() would return any the containing HTML as well which might not be of your interest.

    Have you considered as well to use the <input type="radio"> to force a single selection? If you give them all the same name, then they belongs to the same single selection group.

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

Sidebar

Related Questions

Lets Say i have a table like this WEB_LIST_TABLE KEY Value ---------------------------------------- 134 google.com
Let's say i have a table like this: <table cellpadding=0 cellspacing=0 border=0 class=display id=selection>
Say I have this class: @Entity @Table(name=PICTURE) public class Picture{ private String category1, category2;
Let say I have this table, ID Name Order ======== ======== ========= 1 d
Lets say I have this table: PetID Name Age Weight How can I in
Say I have this table schema. ID AccNo Amount Say I have this data
I have this table: id feed_id ... Let's say that I have 500 rows
Lets say I have one table called REVIEWS This table has Reviews that customers
Let's say I have a table Foo . This table has the columns ID
I'm trying to format a table from XML. Lets say I have this line

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.