单击并下拉列表值时禁用单选按钮

时间:2017-09-19 03:03:19

标签: javascript php jquery html mysql

我需要限制单击按钮,并且在下拉列表中选择的值将被禁用

<script type="text/javascript">
 function getVote(int)
 {
 if (window.XMLHttpRequest)
   {// code for IE7+, Firefox, Chrome, Opera, Safari
   xmlhttp=new XMLHttpRequest();
   }
  else
   {// code for IE6, IE5
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
   }

    if(confirm("Your vote is for "+int))
     {
    xmlhttp.open("GET","save.php?vote="+int,true);
    xmlhttp.send();
      }
      else
    {
      alert("Choose another candidate ");   
        }

    }

    function getPosition(String)
    {
     if (window.XMLHttpRequest)
      {// code for IE7+, Firefox, Chrome, Opera, Safari
       xmlhttp=new XMLHttpRequest();
       }
     else
       {// code for IE6, IE5
       xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
       }

      xmlhttp.open("GET","vote.php?position="+String,true);
      xmlhttp.send();
     }
     </script>
      <script type="text/javascript">
      $(document).ready(function(){
        var j = jQuery.noConflict();
          j(document).ready(function()
           {
             j(".refresh").everyTime(1000,function(i){
                 j.ajax({
                  url: "admin/refresh.php",
                  cache: false,
                 success: function(html){
                  j(".refresh").html(html);
              }
               })
              })

              });
           j('.refresh').css({color:"green"});
           });
      </script>
    </head>
       <body bgcolor="tan">

        <div id="mySidenav" class="sidenav">
      <a href="javascript:void(0)" class="closebtn" onclick="closeNav()">&times;</a>
          <a href="student.php">HOME</a>
      <a href="vote.php">VOTE</a>
      <a href="refresh.php">POLL RESULTS</a>
       <a href="logout.php">LOGOUT</a>
    </div>
     <div id="main">
       <span style="font-size:30px;cursor:pointer" onclick="openNav()">&#9776; </span>
      <center> 
   <font color = "white" size="7"> <div id="hihi">ONLINE VOTING SYSTEM</div>
  </font>

   <br><br>

  <br></center><br><br>
 <body>

<div id="page">
   <div id="header">
         <h1>CURRENT POLLS</h1>

      </div>
    <div class="refresh">
    </div>
   <div id="container"> 
    <table width="420" align="center">
     <form name="fmNames" id="fmNames" method="post" action="vote.php" onSubmit="return positionValidate(this)">
   <tr>
          <td>Choose Position</td>
        <td><SELECT NAME="position" id="position" onclick="getPosition(this.value)">
          <OPTION VALUE="select">select
        <?php 
         //loop through all table rows
         while ($row=mysql_fetch_array($positions)){
          echo "<OPTION VALUE=$row[position_name]>$row[position_name]"; 
         //mysql_free_result($positions_retrieved);
         //mysql_close($link);
          }
       ?>
        </SELECT></td>
        <td><input type="submit" name="Submit" value="See Candidates" />
    </td>
    </tr>
    <tr>
        <td>&nbsp;</td> 
      <td>&nbsp;</td>
     </tr>
    </form> 
     </table>
     <table width="500" align="center">
     <form>
   <tr>
           <th>Candidates:</th>
       <th></th>
      <th>Gender</th>

         <th>Grade</th>
           <th></th>
         <th>Section</th>
        </tr>
      <?php
    //loop through all table rows
       //if (mysql_num_rows($result)>0){
      if (isset($_POST['Submit']))
       {
         while ($row=mysql_fetch_array($result)){

   echo "<tr>";
    echo "<td>" . $row['candidate_name']."</td>";
    echo "<td>" . $row['hello']."</td>";
    echo "<td>" .$row['candidate_gender']."</td";
    echo "<td>" . $row['hello']."</td>";
   echo "<td>" . $row['candidate_grade']."</td>";
          echo "<td>" . $row['hello']."</td>";
    echo "<td>" .$row['candidate_section']."</td";
      echo "<td>" . $row['hello']."</td>";
           Print '<td><img src="date:image/jpeg;base64,' .base64_encode($row['image']).'"height="60 width="75 /></td>';

        echo "<td>" . $row['hello']."</td>";
     echo "<td>" . $row['hello']."</td>";
      echo "<td>" . $row['hello']."</td>";

     echo "<td><input type='radio' name='vote' value='$row[candidate_name]' onclick='getVote(this.value)' /></td>";
     echo "</tr>";
     }

      mysql_free_result($result);
    mysql_close($link);
     //}
         }
     else
    // do nothing
            ?>

保存PHP:

<?php require('connection.php'); 
$vote = $_REQUEST['vote'];
mysql_query("UPDATE tbCandidates SET candidate_cvotes=candidate_cvotes+1 WHERE candidate_name='$vote'"); mysql_close($con); ?>

如何限制用户投票。我是否需要禁用用户单击的下拉列表值并禁用已禁用的单选按钮?请帮帮我。谢谢你希望我能完成这个。 :(

0 个答案:

没有答案