Solved

remove specific row from html table and array/string manipulation

Posted on 2003-11-26
4
995 Views
Last Modified: 2011-10-03
Ok here goes,

I have a javascript which creates rows in a table based on form entries which works with no problem, now I need to delete rows but I can only seem to delete the first and last row in the table!  

is there some way to set the row "id" and delete rows based on that id?

Also if you havppen to have a link to a tutorial on string and array manipulation I would appreciate it as I need to do things in javascript I do in perl like push, pop, split, join, .=, etc...
0
Comment
Question by:acameron
[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
  • 2
4 Comments
 
LVL 5

Expert Comment

by:apparition
ID: 9826676
String functions can be found here
http://www.jimparshall.net/javascript/javascript_strings.aspx

you can hide rows in table with
document.getElementById(<tableid>).rows
[<rownum>].style.visibility="hidden";
0
 
LVL 10

Accepted Solution

by:
NetGroove earned 125 total points
ID: 9826801
Here the remove row code:

<html>
<head>
<script>
function delRow(theButton){
  theTab = document.getElementsByTagName('table')[0].firstChild;
  rNum = theButton.form.rowNum.value;
  theTab.rows[rNum].removeNode();
}
</script>
</head>
<body>
<form>
<input type=text name="rowNum" size="1">
<input type=button value="Del" onClick="delRow(this)">
</form>
<table border="1">
<tr><td>0</td></tr>
<tr><td>1</td></tr>
<tr><td>2</td></tr>
<tr><td>3</td></tr>
<tr><td>4</td></tr>
<tr><td>0</td></tr>
</table>
</body>
</html>


0
 
LVL 10

Expert Comment

by:NetGroove
ID: 9826867
0
 
LVL 25

Expert Comment

by:devic
ID: 9827054
delete without calculation here and this :)

======================
<table cellspacing=0 cellpadding=0 border=1>
<tr><td>0</td><td style=color:red;cursor:hand onclick=parentNode.removeNode()>X</td></tr>
<tr><td>1</td><td style=color:red;cursor:hand onclick=parentNode.removeNode()>X</td></tr>
<tr><td>2</td><td style=color:red;cursor:hand onclick=parentNode.removeNode()>X</td></tr>
<tr><td>3</td><td style=color:red;cursor:hand onclick=parentNode.removeNode()>X</td></tr>
<tr><td>4</td><td style=color:red;cursor:hand onclick=parentNode.removeNode()>X</td></tr>
<tr><td>5</td><td style=color:red;cursor:hand onclick=parentNode.removeNode()>X</td></tr>
</table>
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

In this article, we'll look how to sort an Array in JavaScript, including the more advanced techniques of sorting a collection of records either ascending or descending on two or more fields. Basic Sorting of Arrays First, let's look at the …
This article will give core knowledge of JavaScript and will head in to your first JavaScript program. I am Durvesh Naik and I am here to deal with this series of JavaScript. I will teach you JavaScript in part wise , as its quite boring to read big…
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…

734 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