javascript - delete row

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • idorjee
    New Member
    • Mar 2007
    • 76

    javascript - delete row

    hi,
    i have a problem with my php+javascript, and i am new to both. the script takes input, and displays them into separate tables. i following script does a part of what i wanted to do, ie, it deletes the table sitting inside another one as a row, but it does it for just the first one if i have, lets say, 3 input. the two other delete buttons don't work at all. please help me figure out what's wrong, and how can i fix it.
    thanks a lot in advance.

    Code:
    <html>
    <head>
    <script type="text/javascript">
    function deleteRow(r){
            var i=r.parentNode.parentNode.rowIndex;
            document.getElementById('myTable').deleteRow(i);
    }
    </script>
    </head>
    <?php
    $NUM = $_POST["NUM"];
    if (!$NUM){
    ?>
            <form action="./script.php" method="post">
            <textarea name="NUM" rows="8" cols="60"></textarea>
            <BR>
            <input type="submit" value="Click here to search">
            <input type="reset" value="Clear" >
            </form>
            <?php  
    }else{
    $NUM = $_POST["NUM"];
    $array = preg_split ("/[\s]+/", $NUM);
    foreach ($array as $number) {
    $number = trim($number);
    $text_info = curl_init("http://domain.com/$number");
    ....
    (parse the data and let's say assign a value to $info)
    ....
    echo "<TABLE BORDER=0 ID=\"myTable\" WIDTH=500>";
    echo "<TR><TD>";
    echo "<TABLE BORDER=1>";
    echo "<TR><TD><B>Info:</B></TD><TD> $info </TD></TR>";
    echo "</TABLE></TD>";
    echo "<TD><input type=\"button\" value=\"Delete\" onclick=\"deleteRow(this)\"></TD></TR>";
    echo "</TABLE>";
    }
    }                
    ?>
  • acoder
    Recognized Expert MVP
    • Nov 2006
    • 16032

    #2
    Do you get an error? Show the HTML output for three rows, i.e. what you can see in the browser.

    Comment

    • idorjee
      New Member
      • Mar 2007
      • 76

      #3
      i don't get any kinda error messages on the browser. it's just that only one of the tables get deleted (ie the first one), and doesn't do the same for the next tables when i click the delete button for it. the bit of javascript at the top seems do it's thing just once and than nothing. by the way, my output on the browse is just html tables in rows with a delete button as <td> part of the each row. thanks.
      i would appreciate your help with this.
      Last edited by idorjee; Feb 18 '08, 07:32 PM. Reason: addition of info

      Comment

      • acoder
        Recognized Expert MVP
        • Nov 2006
        • 16032

        #4
        I tested this with a table with three rows, e.g.
        [html]<TABLE BORDER=0 ID="myTable" WIDTH=500>
        <TR>
        <TD>
        <TABLE BORDER=1>
        <TR>
        <TD><B>Info:</B></TD>
        <TD> Test </TD>
        </TR>
        </TABLE>
        </TD>
        <TD><input type="button" value="Delete" onclick="delete Row(this)"></TD>
        </TR>
        <TR>
        <TD>
        <TABLE BORDER=1>
        <TR>
        <TD><B>Info:</B></TD>
        <TD> Test 2 </TD>
        </TR>
        </TABLE>
        </TD>
        <TD><input type="button" value="Delete" onclick="delete Row(this)"></TD>
        </TR>
        <TR>
        <TD>
        <TABLE BORDER=1>
        <TR>
        <TD><B>Info:</B></TD>
        <TD> Test 3 </TD>
        </TR>
        </TABLE>
        </TD>
        <TD><input type="button" value="Delete" onclick="delete Row(this)"></TD>
        </TR>
        </TABLE>[/html]and it works fine.

        Comment

        Working...