禁用所选的下拉列表值并获取下拉列表的下一个值

时间:2017-09-22 08:21:02

标签: javascript php jquery html mysql

enter image description here

  <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>

我需要禁用所选下拉列表的值,并在选择单选按钮时获取下一个下拉列表值的下一个值我该怎么办?请帮忙

  if (isset($_POST['Submit']))
  {
while ($row=mysql_fetch_array($result)){

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

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

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

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

       Print '<td><img src="date:image/jpeg;base64,' .base64_encode($row['image']).'"height="60 width="75 /></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
 ?>
 <tr>

1 个答案:

答案 0 :(得分:0)

不确定这是否是您要实现的目标。使用Jquery完成了以下操作,我删除了您正在使用的侵入式JavaScript。

$('input:radio').each(function() {
    $(this).on('click', function(e) {
        $('#position option[value="' + $(this).val() + '"]').prop('selected', true);
    });
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>

Choose Position
<SELECT NAME="position" id="position">
    <OPTION VALUE="none">Please select</option>
    <OPTION VALUE="name1">some value</option>
    <OPTION VALUE="name2">another value</option>
    <OPTION VALUE="name3">yet another value</option>
</SELECT>

<input type='radio' name='vote' value='name1' />
<input type='radio' name='vote' value='name2' />
<input type='radio' name='vote' value='name3' />
<input type="submit" name="Submit" value="See Candidates" />