php - 如果我单击重置按钮重置不同表单上的单选按钮,我如何清除可能的表数据

标签 php javascript

我想要的是如果我点击我的重置按钮,它会重置我的单选按钮并清除它在可能表数据上的值....我应该在我的代码中添加什么......

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='';

}

例如,document.getElementsByName('president') 用于我的编辑表单上的重置按钮和 document.getElementById('president')用于我的表数据,它在另一种形式上。如果我单击重置,是否有可能在我的函数中调用两个表单?请帮助...

这是我的 select_candidate.php

<script type="text/javascript">
<!--
function  clear(){
    var elems = document.getElementsByName('president');
    for(i=0;i<elems.length;i++)
        elems[i].checked=false;
    document.list.editform.president.value='';

}
function get_president_value()
{
    for (var i=0; i < document.list.president.length; i++)
    {
        if (document.list.president[i].checked)
        {
            return document.getElementById('president').innerHTML = document.list.president[i].value;
        }
    }
}
-->
</script>
<form method="post" name="list">
    <div id="TabbedPanels1" class="TabbedPanels" >
        <ul class="TabbedPanelsTabGroup">
            <li class="TabbedPanelsTab" tabindex="0">President</li>
        </ul>
    <div class="TabbedPanelsContentGroup">
    <div class="TabbedPanelsContent"> 
        <fieldset>
            <legend>President</legend>
<?php require_once('candidate/president.php'); ?>   
        </fieldset></div>
</form>

<!-- here the value of my radio button will appear on this table data and this is where i want to clear as i click my reset button which clears also my radio buttons... -->
<div>
    <fieldset>
        <legend>List of Your Candidates</legend>
        <table>
            <tr><td>President: </td> <td id="president" onclick="clear()"> </td> </tr>
        </table>
    </fieldset>
</div>

这是我的 president.php

   <?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);
                }   

关于php - 如果我单击重置按钮重置不同表单上的单选按钮,我如何清除可能的表数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14350563/

相关文章:

javascript - 如何摆脱 koa-router 添加的未定义的 "phantom"路由

javascript - jQuery 在两个函数之间单击/切换

php - 空字符串不等于 PHP 三元运算符表达式中的空字符串

javascript - 我需要一个 html 音频元素来使用网络音频 api 播放歌曲吗

javascript - 如何在 Protractor 测试中访问 Angular 对象

php - 如何使用 jQuery.parseJSON 绕过换行符

javascript - 如何解码 javascript 打包代码

php - 在带有列名的关联数组中循环

PHP:通过 parent::method() 与 $this->method() 从子类调用方法的区别

php - 类 App\Repositories\UserRepository 不存在