FREE tutorial,solution,RSS Feeds on Operating Systems, Programming, Web Development, Applications, Databases, Networking, Hardware, Security, SEO Free Expertsforge Membership
Join us as Moderator
Submit Article to Expertsforge.com Submit Article My Expertsforge
 
RSS Feeds, Help Help RSS Feeds
bannertop
 

JavaScript Tutorial: Dynamically deleteing columns from a table using Javascript

jawahar
11/21/2005 9:54:39 PM, Views: 2026
The follwing code can be used to dynamically delete columns in a table using HTML and Javascript

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<meta http-equiv="Content-Style-Type" content="text/css">
<meta http-equiv="Content-Script-Type" content="text/javascript">
<style type="text/css">
<!--
td {
background-color: #CCCCCC;
}
-->
</style>
<script type="text/javascript">
function deleteC(c){
var root = c.parentNode.parentNode;//tbody or table - correction if tbody is not present
var allRows = root.getElementsByTagName('tr');// rows collection in the table
var aCells = c.parentNode.getElementsByTagName('td')//cells collection in this row
for(var j=0;j<aCells.length;j++){
if(c==aCells[j]){var q=j;break}//gets the index of this cell in this row
}
for(var i=0;i<allRows.length;i++){
allRows[i].removeChild(allRows[i].getElementsByTagName('td')[q]);//removes the correspondent cells with the same index in their rows
}
}
</script>
</head>
<body>
<table width="100%" border="0" cellspacing="2" cellpadding="2">
<tbody>
<tr>
<td>c0 <a href="#" onclick="deleteC(this.parentNode)">delete this column</a></td>
<td>c1 <a href="#" onclick="deleteC(this.parentNode)">delete this column</a></td>
<td>c2 <a href="#" onclick="deleteC(this.parentNode)">delete this column</a></td>
<td>c3 <a href="#" onclick="deleteC(this.parentNode)">delete this column</a></td>
</tr>
<tr>
<td>c0</td>
<td>c1</td>
<td>c2</td>
<td>c3</td>
</tr>
</tbody>
</table>

</body>
Next Steps:
Add this Tutorial to:
Blink Blink del.icio.ous Del.icio.us Digg Digg
Fark Fark Furl Furl Google Google
Reddit Reddit Simpy Simpy Spurl Spurl
Technorati Technorati Windows Live Win Live Yahoo Yahoo
Rate Me!
Avg Visitor Rating: Average Visitor Rating is 3.5 out of 5
Number of Ratings : 4 Votes
Rate:
Send Private MessageSend Message
Signup / Login To View the Solution or Provide Comments
Post Comment/Solution
Comment:*
        (Link Rules) 
  Use : [bold] for <b>; [/bold] for </b>; [italic] for <i>; [/italic] for </i>; [code] & [/code] for code
 
Categories
Options
JavaScript RSS Feed
Most Popular Tutorial
Most Popular Solution
Top Rated
Top Contributors
Yearly
Overall
 
1. jawahar (300)
bnrtop