doushou3814 2013-03-10 04:35 采纳率: 100%
浏览 63

选中第1组单选按钮的值时,显示第2组单选按钮

What I want is, when I checked the first set of radio button (name = source; value from database), they can show the second set of radio button (name = exam; the value also from database)

<?php 

$sql = 'SELECT * FROM source'; 
$query = mysql_query($sql); 

while ($row =mysql_fetch_array($query)) {
   echo '<input type="radio" name="source" value="'.$row['s_id'].'">'.$row['s_desc']; 
   }

*if ($source.checked){
echo '<input type="radio" name="exam" value="'.$row['e_id'].'">'.$row['e_desc']; 
   }
}*
?>
  • 写回答

1条回答 默认 最新

  • ds08541 2013-03-10 04:44
    关注

    $source is not defined in this extract. Do you mean $row['checked']?

    Perhaps it would help to check that the values returned by the query are in fact the values that you expect to see. If you use the following lines, it will temporarily break your layout, but it will help you confirm that your query is functioning as expected.

    while ($row=mysql_fetch_array($query)) {
      echo '<input type="radio" name="source" value="'.$row['s_id'].'">'.$row['s_desc'];
    
      echo '<br />checked: '.$row['checked'];
      echo '<br />e_id: '.$row['e_id'];
      echo '<br />e_desc: '.$row['e_desc'];
      }
    

    Where are you "checking" the state of rb1? My current guess is that the end user will be checking a radio button in an HTML page served by your PHP script... but you are looking in a database on the server for information on the locally checked state of the button. If my guess is right, you don't want to serve the page again after each click. Instead you can serve the page with all the possible buttons, and use CSS to hide the rb2 buttons whose rb1 button is not selected.

    CAUTION: UNTESTED PHP

    while ($row=mysql_fetch_array($query)) {
      echo '<input type="radio" name="source" value="'.$row['s_id'].'"';
      echo 'onclick=yourJavaScriptFunctionToDisplayTheRB2Button()';
      echo '>'.$row['s_desc'];
    
      echo '<input type="radio" name="exam" value="'.$row['e_id'].'"';
      if (!$row['checked']) {
        echo ' style="visibility=hidden"';
      }
      echo '>'.$row['e_desc'];
      }
    

    For yourJavaScriptFunctionToDisplayTheRB2Button(), see the jsFiddle example here.

    评论

报告相同问题?

悬赏问题

  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 关于大棚监测的pcb板设计
  • ¥15 stm32开发clion时遇到的编译问题
  • ¥15 lna设计 源简并电感型共源放大器
  • ¥15 如何用Labview在myRIO上做LCD显示?(语言-开发语言)
  • ¥15 Vue3地图和异步函数使用
  • ¥15 C++ yoloV5改写遇到的问题