473,411 Members | 2,530 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,411 software developers and data experts.

Selecting a particular row from a html table dynamically created

27
Hi,

I have a html table that has its rows dynamically created. My first column contains radio buttons. I want to get the row for which the radio button is selected.


Spooky
Apr 22 '08 #1
2 3789
acoder
16,027 Expert Mod 8TB
Show your code. What have you tried so far?
Apr 22 '08 #2
here is an example that will work in both firefox and IE. this should give you everything you would want to know about the radio button that was clicked

Expand|Select|Wrap|Line Numbers
  1.  
  2. function radioClicked(btn){
  3.   var tbl,cell,row,rowIndex,cellIndex,tblID;
  4.   cell = btn.parentNode;
  5.   row= cell.parentNode;
  6.   tbl=row.parentNode;
  7.   while(tbl.nodeName!="TABLE")//this is incase the table has a body     tbl=tbl.parentNode;
  8.   rowIndex = row.rowIndex; //starts at 0 so we will add 1 
  9.   rowIndex++;
  10.   cellIndex = cell.cellIndex; //starts at 0 so we will add 1 
  11.   cellIndex++;
  12.   tblID = tbl.id;
  13.   alert("A radio button has been clicked in row " + rowIndex + " cell " +  cellIndex + " in table whos id is " + tblID);
  14. }
  15.  
  16.  
[HTML]
<table id='Table1' border=1>
<tr>
<td><input name='btn' onclick='radioClicked(this)' type='radio'/>radio button</td>
<td><input name='btn' onclick='radioClicked(this)' type='radio'/>radio button</td>
</tr><Tr>
<td><input name='btn' onclick='radioClicked(this)' type='radio'/>radio button</td>
<td><input name='btn' onclick='radioClicked(this)' type='radio'/>radio button</td>
</tr><tr>
<td><input name='btn' onclick='radioClicked(this)' type='radio'/>radio button</td>
<td><input name='btn' onclick='radioClicked(this)' type='radio'/>radio button</td>
</tr>
</table><br>
<table id='Table2' border=1>
<tr>
<td><input name='btn' onclick='radioClicked(this)' type='radio'/>radio button</td>
<td><input name='btn' onclick='radioClicked(this)' type='radio'/>radio button</td>
</tr><Tr>
<td><input name='btn' onclick='radioClicked(this)' type='radio'/>radio button</td>
<td><input name='btn' onclick='radioClicked(this)' type='radio'/>radio button</td>
</tr><tr>
<td><input name='btn' onclick='radioClicked(this)' type='radio'/>radio button</td>
<td><input name='btn' onclick='radioClicked(this)' type='radio'/>radio button</td>
</tr>
</table>
[/HTML]
Apr 22 '08 #3

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

Similar topics

5
by: Axial | last post by:
Question: How to select columns from Excel-generated XML when some cells are empty. I've found examples where rows are to be selected, but I can't seem to extrapolate from that to selecting...
10
by: Free-Ed, Ltd. | last post by:
I am going nuts trying to find a paragraph in a book that described how to change the text content (HTML) in a DIV. Actually I have an array of HTML strings that I want to drop into the DIV,...
1
by: Bill Nedell | last post by:
I am trying to write a PL/PgSQL function that can be given a table name as an argument at execution time and I don't see any way of doing it. I want the user to be able to specify the table...
2
by: buran | last post by:
Dear ASP.NET Programmers, I have a HTML table (running as server control with the control ID: tblInsertSP). The table has 16 rows with textboxes. Depending on the value of the ddlSPType, which...
4
by: Zuel | last post by:
Hi Folks. So I have a small problem. My DoPostBack function is not writen to the HTML page nor are the asp:buttons calling the DoPostBack. My Goal is to create a totaly dynamic web page where...
1
by: Marcus | last post by:
I have a problem maybe one of you could help me with. I've created a data entry screen with lots of dynamically-created client-side controls. I create HTML texboxes client-side by assigning a...
8
by: Jackson | last post by:
I want a class that will determine its base class by the argument passed in. What I am about to write _does_not_work_, but it shows what I am trying to do. class ABC(some_super): def...
6
by: Ros_Au | last post by:
I create a table dynamically using VB, How do I get HTML code for that table into a string variable ??? any sugestion, Thanks!!!
6
by: chindanoor | last post by:
I have a JSP page that dynamically lists records in a table from my database. At the left hand side of each row in the table, there are checkboxes for the user to select a particular record that...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.