
October 28th, 2009, 12:44 PM
|
|
Contributing User
|
|
Join Date: Jul 2009
Posts: 83
Time spent in forums: 13 h 53 m 8 sec
Reputation Power: 1
|
|
|
Dynamically Delete/Selectall rows through checkBox
Hey,
I echo out a csv file in table format on a php page. Below this table I have two buttons 'Delete' and 'Select All'. Where on clicking delete, delete that particular row and on select all, select all the rows of that table.
When I googled, I got the below javascript code to make something like this to work.
Code:
<html>
<head>
<script type="text/javascript">
function deleteRow(tableID){
try{
var table = document.getElementById(tableID);
var rowCount = table.rows.length;
for(var i=0; i<rowCount; i++){
var row = table.rows[i];
var chkbox = row.cells[0].childNodes[0];
if(null != chkbox && true == chbox.checked){
table.deleteRow(i);
rowCount--;
i--;
}
}catch(e){
alert(e);
}
}
</script>
</head>
But in my case, I upload a csv file in page1.php and display the contents in table format along with Delete and Selectall button in page 2.php.
page2.php code
PHP Code:
<html>
<body>
<div align="center">
<?php
if(move_uploaded_file($tmpname,$name)){
if(file_exists($name)){
echo "<table border = 1>\n";
$row = 0;
$fp = fopen($name, "r");
while(($data = fgetcsv($fp, 1000, ",")) !== FALSE){
if($row == 0){
$num = count($data);
echo "<thead>\n<tr>";
$row++;
...
....
....
?>
<p>
<input type="button" value="Delete">
<input type="button" value="Select all"></p>
</div>
</body>
</html>
I didn't know how to edit it to my requirement (adding the checkbox to my existing table and working of delete and selectall option )
I need help coz I'm not that good at Javascript.
|