目標是使用調用java腳本函數清除字段(this.id)的ON CLICK事件清除字段清除字段然後可以接收新值。當按下UPDATE按鈕時,數據庫用新值更新。清除現場功能成功清除現場,如何輸入新值?初始值清除後,如何在輸入欄中輸入新值?
<html>
<head>
<script src="JavaScript/getVal.js" type="text/javascript"></script>
</head>
<body>
<a href="poll.html">Poll</a>
<?php
$connection = mysqli_connect("localhost", "root", "");
mysqli_select_db($connection, "ukelection2015");
$rs = mysqli_query($connection, "select * from poll");
?>
<hr>
<table border=1 id="myTable">
<tr>
<th>Name</th>
<th>Value</th>
<th>Color</th>
<th></th>
<th> </th>
</tr>
<?php
$id = 0;
while ($row = mysqli_fetch_array($rs)) {
print("<form method= 'post' action= 'updatePoll.php'>");
for ($x = 0; $x <= 2; $x++) {
if ($x == 0) {
print("<tr>");
} else {
print("<td>" . $row['name'] . "</td>" . "<td id= '".$id."' value = '" . $row['value'] . "' onclick = 'clearField(this.id)'>" . $row['value'] . "</td>" . "<td>" . $row['color'] . "</td>" . "<td><a href = ''>Update</a></td>");
$x++;
if ($x == 1) {
print "</tr>";
}
$id++;
}
}
// this hidden field is used in updatePoll.php to get the party name to update (i.e. $name=$_POST['name'];)
/* print("<input type='hidden' name ='name' value={$row['name']}>"); */
print("<tr>");
// name
// value
// color
/* print("<td><input type='submit' value='Update' onclick='alertMsg()'/></td>"); */
print("</tr>");
print("</form>");
}
mysqli_close($connection);
?>
</table>
</body>
</html>
This is the javascript function
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
function clearField(anId) {
document.getElementById(anId).innerHTML = 0;
}
謝謝你們,你們指出了我的正確方向。我想我已經找到了答案。這是一個html5屬性; contenteditable ='true'我插入的內容如下 – Tony75
print(「」。$ row ['name']。「」。「