Solved

remove specific row from html table and array/string manipulation

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

Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

Question has a verified solution.

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

This article discusses the difference between strict equality operator and equality operator in JavaScript. The Need: Because JavaScript performs an implicit type conversion when performing comparisons, we have to take this into account when wri…
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…

691 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