douhui2307 2014-04-24 13:09
浏览 206
已采纳

如何将变量值赋给单选按钮

My code looks like that:

foreach($options as $option) {

?>

<input type="radio" name="option" value=<?php $option ?>><?php echo $option?><br>


<?php }?>

<input name= "submit" type="submit" value="Vasta">
</form>

But it does not give the result I want. How could I give radio buttons value of variable $option? This question might have to little information about problem, if it is necessary i post more of my code.

When I change value=<?php $option ?> to value='dog' everything works the way I want, the value will be given.

  • 写回答

2条回答 默认 最新

  • dongyudun6465 2014-04-24 13:10
    关注

    You're missing your echo statement. I also suspect you have spaces in your values which breaks your HTML because you are not using quotes around those values:

    <input type="radio" name="option" value="<?php echo $option ?>"><?php echo $option?><br>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 乌班图ip地址配置及远程SSH
  • ¥15 怎么让点阵屏显示静态爱心,用keiluVision5写出让点阵屏显示静态爱心的代码,越快越好
  • ¥15 PSPICE制作一个加法器
  • ¥15 javaweb项目无法正常跳转
  • ¥15 VMBox虚拟机无法访问
  • ¥15 skd显示找不到头文件
  • ¥15 机器视觉中图片中长度与真实长度的关系
  • ¥15 fastreport table 怎么只让每页的最下面和最顶部有横线
  • ¥15 java 的protected权限 ,问题在注释里
  • ¥15 这个是哪里有问题啊?