[Webinar] Streamline your web hosting managementRegister Today

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 18478
  • Last Modified:

How to get html table's particular column value?

Hi,

I am writing a javascript function to delete a row from a table filled with data. How to get one of the html table's column values so that I can delete the selected row?

Please give answer with code.
0
limct
Asked:
limct
  • 4
  • 2
1 Solution
 
ZvonkoSystems architectCommented:
Like this:


<html>
<head>
<script>
function showCells(){
  rows = document.getElementsByTagName("TABLE")[0].rows;
  for(i=0;i<rows.length;i++){
    cells = rows[i].cells;
    for(j=0;j<cells.length;j++){
      alert(i+"-"+j+": "+cells[j].innerHTML);
    }
  }
}
</script>
</head>
<body>
<a href="javascript:showCells()">Show</a>
<table>
<tr><td>A</td><td>B</td><td>C</td></tr>
<tr><td>D</td><td>E</td><td>F</td></tr>
<tr><td>G</td><td>H</td><td>I</td></tr>
</table>
</body>
</html>


0
 
ragerinoCommented:
do you want to delete the rows in the html-table or do you want to do a delete of the data in the background on the server

if you just want to delete the html-table-row put this td in your table
--------------------------------------------------------------------------------
....
<td><a href="javascript:void null;" onclick="var e=this;while(e.tagName!='TR'){e=e.parentNode};if(e){e.parentNode.removeChild(e);}">[del]</a></td>
....
--------------------------------------------------------------------------------

you can also make a function:

put this to your head
-------------------------------------------------
<script type="text/javascript">
function delRow(e){
  //first find the tablerow
  while(e && e.tagName!='TR')
     e=e.parentNode;
  //if found then remove it form the table (e.parentNode='TBODY')
  if(e)
    e.parentNode.removeChild(e);
}
</script>
--------------------------------------------------------------------------------


then the tablecell can look like this:
--------------------------------------------------------------------------------
....
<td><img src="yourdelicon.gif" border=0 style="cursor:pointer;" onclick="delRow(this);"></td>
....
--------------------------------------------------------------------------------

hope this helps and you give me the points :)
0
 
ZvonkoSystems architectCommented:
First item in your member profile ragerino is LotusScript. Are you a PCLP?
0
The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

 
ZvonkoSystems architectCommented:
Thanks for points and grading.

ragerino, wir sehen uns ;-)
0
 
ZvonkoSystems architectCommented:
Sorry Alex, I confused your member name with another guy.
0
 
ragerinoCommented:
hehe :)
0

Featured Post

The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

  • 4
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now