dos8244 2014-05-08 13:26
浏览 21
已采纳

选择单选按钮时,从隐藏输入字段中检索值

I have a table name courses

courses('course_id','course_name','course_desc')

I am using php. I have 2 rows of record in this table. And I have used a while loop to list the two as radio button options. I want to add a hidden input field that posts the related course_id to the course selected in the radio button. What I have right now is.

 while($row = mysql_fetch_assoc($result)){
          echo '<td><input type="hidden" name="courseid" value="'.$row['course_id'].'"><strong class="panel-title">'.$row['coursename'].'</strong> - '.$row['course_desc'].'<br><input type="radio" name="'.$row['coursename'].'" value="'.$row['coursename'].'"> - Choose '.$row['coursename'].'</td></tr>';

The related hidden input wont get selected when I select 1 of the course. How to achieve that. I hope it would be possible without use of jquery as much as possible.

  • 写回答

2条回答 默认 最新

  • dougutuo9879 2014-05-08 13:45
    关注

    You should put that course_id in value of radio field, so that you will get it posted with your form and by that course_id you can easily retrieve course_name

    while($row = mysql_fetch_assoc($result)){
          echo '<td>'.
                   '<strong class="panel-title">'.$row['coursename'].'</strong> - '.
                    $row['course_desc'].'<br><input type="radio" name="'.$row['coursename'].'" value="'.$row['course_id'].'"> '.
                   '- Choose '.$row['course_name']
               .'</td>';
    

    OR

    If you want to have course_name as well then you can change your value to something like this

    ... value="'.$row['course_id'].'-'.$row['course_name'].'" ...
    

    and then you can easily break it to get course_id and course_name in PHP or JavaScript

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 乌班图ip地址配置及远程SSH
  • ¥15 怎么让点阵屏显示静态爱心,用keiluVision5写出让点阵屏显示静态爱心的代码,越快越好
  • ¥15 PSPICE制作一个加法器
  • ¥15 javaweb项目无法正常跳转
  • ¥15 VMBox虚拟机无法访问
  • ¥15 skd显示找不到头文件
  • ¥15 机器视觉中图片中长度与真实长度的关系
  • ¥15 fastreport table 怎么只让每页的最下面和最顶部有横线
  • ¥15 R语言卸载之后无法重装,显示电脑存在下载某些较大二进制文件行为,怎么办
  • ¥15 java 的protected权限 ,问题在注释里