?
Solved

remove specific row from html table and array/string manipulation

Posted on 2003-11-26
4
Medium Priority
?
997 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 500 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

Optimize your web performance

What's in the eBook?
- Full list of reasons for poor performance
- Ultimate measures to speed things up
- Primary web monitoring types
- KPIs you should be monitoring in order to increase your ROI

Question has a verified solution.

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

This article shows how to create and access 2-dimensional arrays in JavaScript.  It includes a tutorial in case you are just trying to "get your head wrapped around" the concept and we'll also look at some useful tips for more advanced programmers. …
Introduction HTML checkboxes provide the perfect way for a web developer to receive client input when the client's options might be none, one or many.  But the PHP code for processing the checkboxes can be confusing at first.  What if a checkbox is…
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…
Suggested Courses

777 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