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 有没有可以帮我搞一个微信建群链接,包括群名称和群资料群头像那种,不会让你白忙
  • ¥15 stm32开发clion时遇到的编译问题
  • ¥15 lna设计 源简并电感型共源放大器
  • ¥15 如何用Labview在myRIO上做LCD显示?(语言-开发语言)
  • ¥15 Vue3地图和异步函数使用
  • ¥15 C++ yoloV5改写遇到的问题
  • ¥20 win11修改中文用户名路径
  • ¥15 win2012磁盘空间不足,c盘正常,d盘无法写入
  • ¥15 用土力学知识进行土坡稳定性分析与挡土墙设计
  • ¥70 PlayWright在Java上连接CDP关联本地Chrome启动失败,貌似是Windows端口转发问题