Deleting rows from a table with button

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Gary  Dickinson

    #1

    Deleting rows from a table with button

    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.deleteR ow() 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

  • RobG

    #2
    Re: Deleting rows from a table with button

    Gary Dickinson wrote:[color=blue]
    > 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.deleteR ow() 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[/color]

    It's actually at:

    <URL:http://24.84.131.118/modelviewer/loader.js>
    [color=blue]
    > javascript so all help will be greatly appreciated
    >[/color]

    Your onclick is;

    <td><input type='button' value='X' onclick='
    mytable.deleteR ow()
    '>
    </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.toUp perCase() ) {
    x = x.parentNode;
    }
    var i = x.rowIndex;
    while ('TABLE' != x.nodeName.toUp perCase() ) {
    x = x.parentNode;
    }
    x.deleteRow(i);
    }



    --
    RobG

    Comment

    Working...