Php 如果我单击重置按钮(重置不同表单上的单选按钮),如何清除表格数据
我想要的是,如果我单击我的重置按钮,它将重置我的单选按钮并清除其在表数据上的值。。。。我应该在我的代码中添加什么Php 如果我单击重置按钮(重置不同表单上的单选按钮),如何清除表格数据,php,javascript,Php,Javascript,我想要的是,如果我单击我的重置按钮,它将重置我的单选按钮并清除其在表数据上的值。。。。我应该在我的代码中添加什么 function clear(){ var elems = document.getElementsByName('president') && document.getElementById('president'); for(i=0;i<elems.length;i++) elems[i].checked=false;
function clear(){
var elems = document.getElementsByName('president') && document.getElementById('president');
for(i=0;i<elems.length;i++)
elems[i].checked=false;
document.list.editform.president.value='';
}
这是我的总统
<?php
// get the records from the database
if ($result = $mysqli->query("SELECT * FROM candidate_info WHERE position= 'president'"))
{
// display records if there are records to display
if ($result->num_rows > 0)
{
// display records in a table
echo "<table border='1' cellpadding='10'>";
// set table headers
echo "<tr><th>Student ID</td><th>Course</th><th>Name</th></tr>";
while ($row = $result->fetch_object())
{
// set up a row for each record
echo "<tr>";
echo "<td>" . $row->studid . "</td>";
echo "<td>" . $row->course . "</td>";
echo "<td>" . $row->fname . " ". $row->mname ." ". $row->lname ." </td>";
echo "<td><input type ='radio' name='president' id='". $row->studid ."' value='" . $row->fname . " ". $row->mname ." ". $row->lname ."' onchange='get_president_value()' ></td>";
echo "</tr>";
}
echo "</table>";
}
// if there are no records in the database, display an alert message
else
{
echo "No results to display!";
}
}
// show an error if there is an issue with the database query
else
{
echo "Error: " . $mysqli->error;
}
// close database connection
$mysqli->close();
// <a href="records.php">Add New Record</a>
?>
//here is my reset button that resets my radio buttons
<form name="editform" method="post">
<input type="reset" name="reset" value="Clear" id="candidate2" onClick="clear()">
</form></div>
Java脚本代码使用tableid.rows.length获取行数;
if(tabLen==1){return;}//其仅平均标头不返回任何数据
其中rowId在创建表时给出类似于“userRow”的rowId字符串;
对于(i=1;i
我们可以看看你的html吗?对于这一点,可能有一种更有效的方法。我在想getElementsByTagName
。另外,根据您目前提供的内容,我几乎不知道您在问什么,也不知道您的页面/html/js如何协调工作。您试图在元素中存储什么?现在您正在使用&&
运算符将其设置为document.getElementById('president')
的返回值,但前提是document.getElementsByName('president')
返回真实值。@mrtsherman。。请帮助我…@Jonathan..我在elems上存储的是重置按钮的名称和表数据的id,但只有重置按钮在“editform”表单上。你能在中创建一个演示吗
<?php
// get the records from the database
if ($result = $mysqli->query("SELECT * FROM candidate_info WHERE position= 'president'"))
{
// display records if there are records to display
if ($result->num_rows > 0)
{
// display records in a table
echo "<table border='1' cellpadding='10'>";
// set table headers
echo "<tr><th>Student ID</td><th>Course</th><th>Name</th></tr>";
while ($row = $result->fetch_object())
{
// set up a row for each record
echo "<tr>";
echo "<td>" . $row->studid . "</td>";
echo "<td>" . $row->course . "</td>";
echo "<td>" . $row->fname . " ". $row->mname ." ". $row->lname ." </td>";
echo "<td><input type ='radio' name='president' id='". $row->studid ."' value='" . $row->fname . " ". $row->mname ." ". $row->lname ."' onchange='get_president_value()' ></td>";
echo "</tr>";
}
echo "</table>";
}
// if there are no records in the database, display an alert message
else
{
echo "No results to display!";
}
}
// show an error if there is an issue with the database query
else
{
echo "Error: " . $mysqli->error;
}
// close database connection
$mysqli->close();
// <a href="records.php">Add New Record</a>
?>
//here is my reset button that resets my radio buttons
<form name="editform" method="post">
<input type="reset" name="reset" value="Clear" id="candidate2" onClick="clear()">
</form></div>
Java Script Code use tableid.rows.length take number of row;
if(tabLen == 1){ return;}//its mean only header remaning no data
where rowId while creating table giving rowId string like "userRow" ;
for (i=1; i< tabLen; i++)
{
if (document.getElementById(rowId+(i-1)) != undefined)
tableToBeDeleted.deleteRow(document.getElementById(rowId+(i-1)).rowIndex);
else if (document.getElementById(rowId+"_New") != undefined)
tableToBeDeleted.deleteRow(document.getElementById(rowId+"_New").rowIndex);
}