RE: php ajax delete row without refresh

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Newer browsers implement the JavaScript DOM Tree model, which provides a
'removeChild' function. This will allow you to identify and remove any
element of the DOM, including a row in a table.

This working example shows you how it works :-


<table id="myTable"> 
<tr> 
<td>Row 0 Cell 1</td> 
<td>Row 0 Cell 2</td> 
</tr> 
<tr> 
<td>Row 1 Cell 1</td> 
<td>Row 1 Cell 2</td> 
</tr> 
<tr> 
<td>Row 2 Cell 1</td> 
<td>Row 2 Cell 2</td> 
</tr> 
</table> 
<a href="#" onclick="remChild(1);return false;">removeChild(1)</a> 
<script> 

function remChild(n) { 
  if (document.getElementById) { 
    var tbl = document.getElementById('myTable'); 
    if (tbl.hasChildNodes()) { 
      var tbdy;

      // Loop through the 'mytable' DOM tree looking for the table body

      for (var i = 0; i < tbl.childNodes.length; i++) { 
        if (tbl.childNodes[i].nodeName == 'TBODY') { 
          tbdy = tbl.childNodes[i]; 
          break; 
        } 
      } 
      if (tbdy.hasChildNodes()) { 
        var row, rowCounter = 0;

      // now loop through the table body looking for the 'n' row and delete
if found

        for (var i = 0; i < tbdy.childNodes.length; i++) { 
          if (tbdy.childNodes[i].nodeName == 'TR') { 
            if (rowCounter == n) { 
              row = tbdy.childNodes[i]; 
              tbdy.removeChild(row); 
              break; 
            } else { 
              rowCounter++; 
            } 
          } 
        } 
      } 
    } 
  } 

} 

</script>  

-----Original Message-----
From: php-objects@xxxxxxxxxxxxxxx [mailto:php-objects@xxxxxxxxxxxxxxx] On
Behalf Of Farhan khalid
Sent: 08 February 2007 00:18
To: phpexperts-owner; php-objects@xxxxxxxxxxxxxxx
Subject:  php ajax delete row without refresh

Hi,

i need to delete a record from database with php, ajax and then remove the
row from table

so if i have records
row1
row2
row3
row4
and i put a check on record row 3 then the row of records row 3 is deleted
and row 4 pushes 1 step upwards to fill the space of row3.

can anyone tell me how to do this?

Regards
Farhan

***********************************************************************************
Any opinions expressed in email are those of the individual and not necessarily those of the company. This email and any files transmitted with it are confidential and solely for the use of the intended recipient 
or entity to who they are addressed. It may contain material protected by attorney-client privilege. If you are not the intended recipient, or a person responsible for delivering to the intended recipient, be advised that you have received this email in error and that any use is strictly prohibited.

Random House Group + 44 (0) 20 7840 8400
http://www.randomhouse.co.uk
http://www.booksattransworld.co.uk 
http://www.kidsatrandomhouse.co.uk
Generic email address - enquiries@xxxxxxxxxxxxxxxxx

Name & Registered Office:
THE RANDOM HOUSE GROUP LIMITED
20 VAUXHALL BRIDGE ROAD
LONDON
SW1V 2SA
Random House Group Ltd is registered in the United Kingdom with company No. 00954009, VAT number 102838980
***********************************************************************************


[Index of Archives]     [PHP Home]     [PHP Users]     [PHP Soap]     [Kernel Newbies]     [Yosemite]     [Yosemite Campsites]

  Powered by Linux