Deleting rows from a table with button

G

Gary Dickinson

Hello Everybody,

I have a table that has a delete button at the end of each row. I want
the row to disappear/delete when the user clicks on the delete button
for the corresponding row. I tried using the command
mytable.deleteRow() for the button but no luck. Here is the url for the
page. http://24.84.131.118/modelviewer/index.html and the javascript
is in http://24.84.131.118/loader.js . This is my first attempt at
javascript so all help will be greatly appreciated


thanks

gary
 
R

RobG

Gary said:
Hello Everybody,

I have a table that has a delete button at the end of each row. I want
the row to disappear/delete when the user clicks on the delete button
for the corresponding row. I tried using the command
mytable.deleteRow() for the button but no luck. Here is the url for the
page. http://24.84.131.118/modelviewer/index.html and the javascript
is in http://24.84.131.118/loader.js . This is my first attempt at

It's actually at:

javascript so all help will be greatly appreciated

Your onclick is;

<td><input type='button' value='X' onclick='
mytable.deleteRow()
'>
</td>


To delete a row, the syntax is table.deleteRow( index ) where 'table'
is a reference to a table and 'index' is the index of one of the rows.

You don't define 'mytable' or provide an index for which row to delete.

Try something like:

<td><input type='button' value='X' onclick='
delRow(this);
'>
</td>

And define delRow in your loader.js as:

function delRow(x) {
while ('TR' != x.nodeName.toUpperCase() ) {
x = x.parentNode;
}
var i = x.rowIndex;
while ('TABLE' != x.nodeName.toUpperCase() ) {
x = x.parentNode;
}
x.deleteRow(i);
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,431
Messages
2,571,677
Members
48,796
Latest member
Greg L.

Latest Threads

Top