Remove row & change id's

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • winterwind
    New Member
    • Oct 2008
    • 2

    Remove row & change id's

    I want to remove one row from table by clicking on remove link(one for each row) and change their id's correspondingly (like remove 2nd row and assign 3rd row id=2nd row id i.e.,shift row id's)
  • RamananKalirajan
    Contributor
    • Mar 2008
    • 608

    #2
    Hello Sir,
    U can delete the particular row with the row index which is autogenerated in the Table, why do u want to change the rowId. I dont get ur point.

    [HTML]<html>
    <head>
    <script type="text/javascript">
    function doThis()
    {
    var myTab = document.getEle mentById('myTab le');
    var row=myTab.rows. length;
    var y=myTab.insertR ow(row);

    var a=y.insertCell( 0);
    var xx= document.create Element('input' );
    xx.type="text";
    a.appendChild(x x);

    var b=y.insertCell( 1);
    var xx= document.create Element('input' );
    xx.type="text";
    b.appendChild(x x);

    var c=y.insertCell( 2);
    var xx= document.create Element('input' );
    xx.type="button ";
    xx.value="Remov e"
    xx.onclick="rem oveThis(this)"
    c.appendChild(x x);
    c.innerHTML = c.innerHTML;
    }

    function removeThis(ths)
    {
    var rIndex = ths.parentNode. parentNode.rowI ndex;
    alert("rIndex = "+rIndex);
    document.getEle mentById('myTab le').deleteRow( rIndex);

    }
    </script>

    </head>
    <body>
    <br/>
    <input type="button" value="Add" onclick="doThis ()">
    <br/>
    <table id="myTable" border="1" cellspacing="5" cellpadding="5" >
    <tr>
    <th>Name</th>
    <th>Wage</th>
    <th></th>
    </tr>
    </table>
    </body>
    </html>[/HTML]

    Regards
    Ramanan Kalirajan

    Comment

    • winterwind
      New Member
      • Oct 2008
      • 2

      #3
      Thanks for kind reply.

      Actually in my code i have Browse....Butto n(i.e. <input type='file'>) and remove(<a href=''>). By clicking on remove link it has to remove current row and like that it has to proceed. I want to check whether every row(every type='file' value) is null('') or some file is selected to upload a file. For that reason it has to remove current selected row and here with row id's problem comes in checking. Plz if u have any idea or code plz forward me..

      Thanks again for ur kind reply




      Originally posted by RamananKaliraja n
      Hello Sir,
      U can delete the particular row with the row index which is autogenerated in the Table, why do u want to change the rowId. I dont get ur point.

      [HTML]<html>
      <head>
      <script type="text/javascript">
      function doThis()
      {
      var myTab = document.getEle mentById('myTab le');
      var row=myTab.rows. length;
      var y=myTab.insertR ow(row);

      var a=y.insertCell( 0);
      var xx= document.create Element('input' );
      xx.type="text";
      a.appendChild(x x);

      var b=y.insertCell( 1);
      var xx= document.create Element('input' );
      xx.type="text";
      b.appendChild(x x);

      var c=y.insertCell( 2);
      var xx= document.create Element('input' );
      xx.type="button ";
      xx.value="Remov e"
      xx.onclick="rem oveThis(this)"
      c.appendChild(x x);
      c.innerHTML = c.innerHTML;
      }

      function removeThis(ths)
      {
      var rIndex = ths.parentNode. parentNode.rowI ndex;
      alert("rIndex = "+rIndex);
      document.getEle mentById('myTab le').deleteRow( rIndex);

      }
      </script>

      </head>
      <body>
      <br/>
      <input type="button" value="Add" onclick="doThis ()">
      <br/>
      <table id="myTable" border="1" cellspacing="5" cellpadding="5" >
      <tr>
      <th>Name</th>
      <th>Wage</th>
      <th></th>
      </tr>
      </table>
      </body>
      </html>[/HTML]

      Regards
      Ramanan Kalirajan

      Comment

      • RamananKalirajan
        Contributor
        • Mar 2008
        • 608

        #4
        Originally posted by winterwind
        Thanks for kind reply.

        Actually in my code i have Browse....Butto n(i.e. <input type='file'>) and remove(<a href=''>). By clicking on remove link it has to remove current row and like that it has to proceed. I want to check whether every row(every type='file' value) is null('') or some file is selected to upload a file. For that reason it has to remove current selected row and here with row id's problem comes in checking. Plz if u have any idea or code plz forward me..

        Thanks again for ur kind reply

        This could help u out, but i dont know wether its ur requirement. Its just a small idea

        [HTML]<html>
        <head>
        <script type="text/javascript">
        function doThis()
        {
        var myTab = document.getEle mentById('myTab le');
        var xx= document.create Element('input' );
        xx.type="file";

        var row=myTab.rows. length;
        var y=myTab.insertR ow(row) ;
        var b=y.insertCell( 0);
        b.appendChild(x x);
        b.innerHTML = b.innerHTML;

        var xy=document.cre ateElement('inp ut');
        xy.type="button ";
        xy.value="Remov e";
        xy.onclick="rem oveThis(this)";
        var c=y.insertCell( 1);
        c.appendChild(x y);
        c.innerHTML=c.i nnerHTML;
        }
        function removeThis(ths)
        {
        var rowIndex = ths.parentNode. parentNode.rowI ndex;
        document.getEle mentById('myTab le').deleteRow( rowIndex);
        }
        </script>
        </head>
        <body>
        <input type="button" value="Attachme nt" onclick="doThis ()">
        <br/>
        <table id="myTable" border="1" cellspacing="5" cellpadding="5" >
        </table>
        </body>
        </html>[/HTML]

        Regards
        Ramanan Kalirajan

        Comment

        Working...