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.
limctAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
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
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

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
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
JavaScript

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.