By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,504 Members | 1,191 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,504 IT Pros & Developers. It's quick & easy.

how to retrieve index Position of a <TD>

syedshaffee
P: 91
hey people,

can someone please suggest me how to retrieve the value of the index position of <TD> at run time to be specific here is the code
Expand|Select|Wrap|Line Numbers
  1. $("#Table_Data tr").click(function(){
  2.    $(this).find(':checkbox').attr('checked', ! $(this).find(':checkbox').attr('checked'));    
  3.    if($(this).find(':checkbox').attr('checked'))
  4.         {
  5.               var index=$(this). 
  6.               var html = '';
  7.     html = $('#clickME td:eq(1)').text();//here i have defined it statically but it needs to be dynamic
  8.     alert(html);
  9.  
  10.  
  11.  
  12.         }
  13.         else
  14.         {
  15.             $(this).removeClass('highlight');
  16.               $(this).addClass('evenrow');
  17.         }
  18. });
my problem:
1) the index value and the text of that index value of <TD> should be according to the users selection meaning i have added a check box in my table

how to apply the same
Jan 20 '12 #1
Share this Question
Share on Google+
10 Replies


Dormilich
Expert Mod 5K+
P: 8,639
do I interpret it right that the desired number is the value of the checkbox?
Jan 20 '12 #2

syedshaffee
P: 91
No,check value is not required i require the cell value of 2nd row
Jan 20 '12 #3

Dormilich
Expert Mod 5K+
P: 8,639
the index value [...] should be according to the users selection
so which is the user's selection then if not the checkbox value?
Jan 20 '12 #4

syedshaffee
P: 91
for example take a google inbox page i m doing something like that when a user selects a row the 2nd cell value of the row should be displayed in a msgbox
Jan 20 '12 #5

Dormilich
Expert Mod 5K+
P: 8,639
if it's always the second cell of the selected row, it is index number 1.
Jan 20 '12 #6

syedshaffee
P: 91
OK i tried that
Expand|Select|Wrap|Line Numbers
  1. $('#clickME td:eq(1)').text();
but when i going and click the second check box its giving me the same value and one more thing the <TD> is dynamically generated from database so i want that when the user clicks on the second check box the value of that 2<TD> should be displayed the code is here
Expand|Select|Wrap|Line Numbers
  1.   <td  ALIGN="left" VALIGN="top" bgcolor="<%=BgColour%>" NOWRAP><input id="Checkbox1" type="checkbox" /></td>
  2.                 <td ALIGN="left" VALIGN="top" bgcolor="<%=BgColour%>" NOWRAP><%=rstAsset("Asset_id") %> </td>
  3.                 <td  ALIGN="left" VALIGN="top" bgcolor="<%=BgColour%>" NOWRAP><%=rstAsset("invoice_no")%> &nbsp; </td>
  4.                 <td ALIGN="left" VALIGN="top" bgcolor="<%=BgColour%>"> <%= rstAsset("invoice_date") %> &nbsp;</td>
  5.                 <td ALIGN="left" VALIGN="top" NOWRAP bgcolor="<%=BgColour%>"><%=rstAsset("Supplier_Name")%> &nbsp;</td>
  6.                 <td ALIGN="left" VALIGN="top" bgcolor="<%=BgColour%>" NOWRAP><%=rstAsset("Asset_type_description")%> &nbsp;</td>
  7.                 <td ALIGN="left" VALIGN="top" bgcolor="<%=BgColour%>"> <%= rstAsset("assettypesubdesc") %> &nbsp;</td>
  8.                 <td ALIGN="left" VALIGN="top" bgcolor="<%=BgColour%>"> <%= rstAsset("Asset_description") %> &nbsp;</td>
  9.                 <td ALIGN="left" VALIGN="top" NOWRAP bgcolor="<%=BgColour%>"> <%=rstAsset("Asset_Serial_no")%> &nbsp;</td>
  10.                 <td ALIGN="left" VALIGN="top" NOWRAP bgcolor="<%=BgColour%>"><%=rstAsset("Asset_barcode_no")%> &nbsp;</td>
  11.                 <td ALIGN="right" VALIGN="top" NOWRAP bgcolor="<%=BgColour%>"> <%=Formatnumber(rstAsset("Asset_purchase_price"))%></td>
  12.                 <td ALIGN="left" VALIGN="top" bgcolor="<%=BgColour%>"> <%= ucase(rstAsset("statedesc")) %>&nbsp; </td>
  13.                 <td ALIGN="left" VALIGN="top" bgcolor="<%=BgColour%>"> <%= ucase(rstAsset("Department_Desc")) %>&nbsp; </td> 
  14.                 <td ALIGN="left" VALIGN="top" NOWRAP bgcolor="<%=BgColour%>"> <%=rstAsset("Cost_Centre_Code")%> &nbsp;</td>
  15.  
how can i do that
-------------------
|check box| | TD |->when he clicks on the check box
+---------+-+-----+ the value of that TD should be displayed
|check box| | TD |
+---------+-+-----+

can u please suggest me for the same or alternative for the same
Jan 20 '12 #7

Dormilich
Expert Mod 5K+
P: 8,639
but when i going and click the second check box
what second checkbox?

when you said "select a row" this seemed to be a click action on the <tr> since you explicitly denied that a checkbox was used. (and for the records, I don't have a google inbox page to look at for comparison)

the <TD> is dynamically generated from database
that is considered static for JavaScript since the content is created before JS starts up.

besides that, when posting HTML code, use the one you get from the browser (via view source code) as any server-side code is absolutely pointless.
Jan 20 '12 #8

syedshaffee
P: 91
i didn't get u friend
Jan 20 '12 #9

Dormilich
Expert Mod 5K+
P: 8,639
in what regard? mind that the only information I have is the one you give me. the clearer the information, the better I can help.
Jan 20 '12 #10

syedshaffee
P: 91
Finally got it man and working great
Jan 23 '12 #11

Post your reply

Sign in to post your reply or Sign up for a free account.