Solved

remove specific row from html table and array/string manipulation

Posted on 2003-11-26
4
991 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
  • 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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Article by: DanRollins
This article describes a JavaScript program that creates a maze made of hexagonal cells.  In Part 2 (http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/A_7850-Hex-Maze-Part-2.html), we'll extend the program by adding a depth-…
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
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…

706 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

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now