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

报告相同问题?

悬赏问题

  • ¥50 切换TabTip键盘的输入法
  • ¥15 关于#网络安全#的问题:求ensp的网络安全,不要步骤要完成版文件
  • ¥15 可否在不同线程中调用封装数据库操作的类
  • ¥20 使用Photon PUN2解决游戏得分同步的问题
  • ¥15 微带串馈天线阵列每个阵元宽度计算
  • ¥15 keil的map文件中Image component sizes各项意思
  • ¥20 求个正点原子stm32f407开发版的贪吃蛇游戏
  • ¥15 划分vlan后,链路不通了?
  • ¥20 求各位懂行的人,注册表能不能看到usb使用得具体信息,干了什么,传输了什么数据
  • ¥15 Vue3 大型图片数据拖动排序