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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T05:42:46+00:00 2026-05-27T05:42:46+00:00

I am dynamically creating a table using JSON so i dont know in advance

  • 0

I am dynamically creating a table using JSON so i dont know in advance how many column and/or rows will be generated.

I add a clicked event for the row that get selected.

Now my every table will have a column name ID

I want to find the value of ID for the selected row.

How can i achieve this?

I have googled a find a lot of sample which select the cell be index but not by column name.

My table is something like:

enter image description here

My table is generated like:

function CreateTableView(objArray, theme, enableHeader) {
// set optional theme parameter
if (theme === undefined) {
    theme = 'mediumTable'; //default theme
}

if (enableHeader === undefined) {
    enableHeader = true; //default enable headers
}

// If the returned data is an object do nothing, else try to parse
var array = typeof objArray != 'object' ? JSON.parse(objArray) : objArray;

var str = '<table class="' + theme + '">';

// table head
if (enableHeader) {
    str += '<thead><tr>';
    for (var index in array[0]) {
        str += '<th scope="col">' + index + '</th>';
    }
    str += '</tr></thead>';
}

// table body
str += '<tbody>';
for (var i = 0; i < array.length; i++) {
    str += (i % 2 == 0) ? '<tr class="alt">' : '<tr>';
    for (var index in array[i]) {
        str += '<td>' + val(array[i][index]) + '</td>';
    }
    str += '</tr>';
}
str += '</tbody>'
str += '</table>';
return str;

}

Any help is appreciated

  • 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-27T05:42:47+00:00Added an answer on May 27, 2026 at 5:42 am

    I hope i understood you correctly but this should do it.
    It alerts the content of the td with the name ID of the clicked tr.

    $('tr').live('click',function(){
        alert( $(this).find('td[name="ID"]').html() );
    });
    

    To find the td via the th with text ID you could do this:

    var index = $('yourtable th:contains("ID")').index();
    alert( $('.selectedRow td:eq('+index+')').html() );
    

    What I would do though is to save the ID in the TR’s data object so you won’t have to pull it out the td but can access it directly, like this:

    [...]
    <tr data-id="26"><td>.....</td></tr>
    [...]
    

    then you can access it like that:

    $('.selectedRow').data('id');
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am creating a large table dynamically using Javascript. I have realised the time
I am dynamically creating a table which I want to have clickable rows. When
i am creating the textboxes dynamically using jquery on a button click. <table width=100%
I am dynamically creating an HTML table by using a repeater. I have four
I am dynamically creating a html table based on the JSON response from an
In My application i need to create a table with dynamically creating Rows based
I am creating a table dynamically based on the number of rows returned from
I am dynamically creating a table in C# with ASP.NET, and each row will
I am having a JSP page, where i am dynamically creating a Table data.
I'm creating a table in an asp.net code behind dynamically, and I want to

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.