2012-03-23 8 views
0

私はphpテーブルを持っていますが、私の選択肢の行を削除したいのですが、これについてどうやって行くのか分かりません。ここに削除するために私のjavascriptです:ここではphp javascript delete個々の行

// When a delete button is pressed in one of the rows 
function deleteCurrentRow(whatrow) 
{ 
    //deletes the approriate row according to what button was pressed 
    if (hasLoaded) { 
    var delRow = whatrow.parentNode.parentNode; 
    deleteRows(delRow);//sends the row for deletion to the function to be deleted 
    } 
} 



function deleteRows(rowforDeletion) 
{ 
    if (hasLoaded) { 

     var rowPos = rowforDeletion.sectionRowIndex;//postion of the row for deletion 
     rowforDeletion.parentNode.deleteRow(rowPos);//deletes row 
     increment = increment -1; 

    } 
} 

は私のPHPのテーブルです:

<table border="1" cellspacing="5" id="tblmarkscheme" style="float: center;"> 
    <thead> 
    <tr> 
     <th colspan="5">Template</th> 
    </tr> 
    <tr> 
     <th>Mark</th><th>Criteria</th><th>Delete</th> 
    </tr> 
    </thead> 
    <tbody> 
    <?php 
     $query = "SELECT maxMark, criteria FROM mark "; 
     $result = mysql_query($query); 


     while ($row = mysql_fetch_array($result)) 
     { 
     echo "<tr>"; 
     echo "<td>" ."<input type = text name = text size = 1 id = mark value = ". $row['maxMark'].">" ."</td>"; 
     echo "<td>"."<textarea>".$row['criteria']. "</textarea>"."</td>"; 
     echo "<td>"."<input type = button value = Delete onclick = deleteCurrentRow(this);/>"."</td>"; 
     echo "</tr>"; 

     } 


    ?> 

    </tbody><!--elements added onload and when button pressed --> 
</table> 

私はボタン

+0

、私が行うために必要なすべてが置かれたのonclickビットで戻り、それ –

答えて

0

ここでの例です。あなたがボタンをクリックすると、その行が削除されますです:

<!DOCTYPE HTML> 
<html> 
    <head> 
     <script type="text/javascript"> 
      var p = { 
       deleteRow: function(row) { 
       document.getElementById("mytable").deleteRow(row.rowIndex); 
       } 
      }; 
     </script> 
    </head> 
    <body> 
     <table id="mytable"> 
      <tr> 
       <td><input type="button" value="row1" onclick="p.deleteRow(this)"/></td> 
      </tr> 
      <tr> 
       <td><input type="button" value="row2" onclick="p.deleteRow(this)"/></td> 
      </tr> 
     </table> 
    </body> 
</html> 
0

を押すことで、テーブルの個々の行を削除したい実際には、HTMLです表。

行を削除するにはjavascriptを使用する必要があります。

http://www.w3schools.com/jsref/met_table_deleterow.asp

+0

W3Cブーに「」を追加します! Hsss!あなたの応答を冗談にするのはたぶんその予定だが、多くの場合それは適切な参照だ。残念なことにクールな子供たちはそれが悪いと思うので、多くの人が段落を読むので悪いと言っている。 – CBusBus

+0

しかし、その中のtheres PHPテーブル行のデータ、私のjavacodeは、PHPの外のテーブル行のために働くでしょう –

+0

私はちょうど私が "JavaScriptのテーブル行を削除する"グーグルで来た最初のことですので、それを置く...私はOPに、この時点で、より良い/より多くの情報を望むなら、十分にそれを知ることに疑いの恩恵を与える。 –

0
<script src="http://code.jquery.com/jquery-1.9.1.js"></script> 
<script> 
function del(id) 
{ 

var info = 'id=' + id; 
    if(confirm("Are you sure you want to delete this Record?")){ 
     var html = $.ajax({ 
     type: "GET", 
     url: "deletCourse.php", 
     data: info, 
     async: false , 
     success: function() { 
    window.location.reload(true);} 
     }).responseText; 


    } 
} 
</script> 

<?php 
$link=mysql_connect("localhost","root","") or die(mysql_error()); 
mysql_select_db("cart"); 
$sql=mysql_query("SELECT * FROM `details`"); 
echo "<table>"; 
echo "<tr><th>Name</th><th>NO of Items</th></tr>"; 
while($row = mysql_fetch_assoc($sql)){ 
    echo '<tr class="record">'; 
    echo "<td>" . $row['name'] . "</td>"; 
    echo "<td>" . $row['num'] . "</td>"; 

    echo '<td><div align="center"><a href="#" id="' . $row['id'] . '" onclick="del('.$row['id'].')">delete</a></div></td>'; 
    echo '</tr>'; 
} 
echo "</table>"; 
mysql_close($link); 
?>`` 
私は愚かされていた
+0

答えを改善するために説明を追加してください。コードはあまり良くありません。 –

関連する問題