2

私が欲しいのは、リセットボタンをクリックすると、ラジオボタンがリセットされ、5月のテーブルデータの値がクリアされることです....ここでコードに何を追加すればよいですか...

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')、他のフォームにあるテーブルデータ用であるとしましょう。リセットをクリックすると、関数で 2 つのフォームが呼び出される可能性はありますか? 助けてください...

これは私の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>
4

1 に答える 1

1
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);
                }   
于 2013-01-17T08:15:43.497 に答える