Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

How to get  html table's particular column value?

Posted on 2004-10-22
6
Medium Priority
?
18,473 Views
Last Modified: 2011-08-18
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
Comment
Question by:limct
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 2
6 Comments
 
LVL 63

Accepted Solution

by:
Zvonko earned 2000 total points
ID: 12378734
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
 
LVL 3

Expert Comment

by:ragerino
ID: 12379270
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
 
LVL 63

Expert Comment

by:Zvonko
ID: 12379344
First item in your member profile ragerino is LotusScript. Are you a PCLP?
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 63

Expert Comment

by:Zvonko
ID: 12379496
Thanks for points and grading.

ragerino, wir sehen uns ;-)
0
 
LVL 63

Expert Comment

by:Zvonko
ID: 12379632
Sorry Alex, I confused your member name with another guy.
0
 
LVL 3

Expert Comment

by:ragerino
ID: 12387553
hehe :)
0

Featured Post

Ask an Anonymous Question!

Don't feel intimidated by what you don't know. Ask your question anonymously. It's easy! Learn more and upgrade.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article discusses how to create an extensible mechanism for linked drop downs.
In this blog, we’ll look at how improvements to Percona XtraDB Cluster improved IST performance.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

610 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question