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

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

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>
    
    已采纳该答案
    打赏 评论
  • dongnan1899 2014-04-24 13:14

    Try using

    value="<?php echo $option ?>">

    打赏 评论

相关推荐 更多相似问题