编辑时如何设置单选按钮的值? [英] How to set the value for Radio Buttons When edit?

查看:31
本文介绍了编辑时如何设置单选按钮的值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个带有单选按钮的性别行,男性和女性.当我第一次注册时,单选按钮的值将存储在数据库中.现在我的问题是,如果我再次编辑该行,它想要来(这意味着检查)该值作为男性/女性.怎么做?

I have a Gender Row with radio buttons male & female. when i register as first time the values of radio button will store in database. Now my question is if i edit that row again it want to come(that means checked) with that value as male/female. how to make it?

注意:使用 php.

HTML 脚本:

<tr id="inside">
<td align="right" width="40%" id="side" >Gender</td>
<td width="3%"> </td>
<td align="left" width="50%">
<input type="radio" name="sex" value="Male" size="17">Male
<input type="radio" name="sex" value="Female" size="17">Female
</td>
</tr>

推荐答案

填充字段时,可以检查值:

When you populate your fields, you can check for the value:

<input type="radio" name="sex" value="Male" <?php echo ($sex=='Male')?'checked':'' ?>size="17">Male
<input type="radio" name="sex" value="Female" <?php echo ($sex=='Female')?'checked':'' ?> size="17">Female

假设您从数据库返回的值在变量 $sex

Assuming that the value you return from your database is in the variable $sex

选中的属性会预选匹配的值

The checked property will preselect the value that match

这篇关于编辑时如何设置单选按钮的值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆