How to set the value for Radio Buttons When edit?(编辑时如何设置单选按钮的值?)
问题描述
我有一个带有单选按钮的性别行,男性和女性.当我第一次注册时,单选按钮的值将存储在数据库中.现在我的问题是,如果我再次编辑该行,它想要来(这意味着检查)该值作为男性/女性.怎么做?
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
这篇关于编辑时如何设置单选按钮的值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:编辑时如何设置单选按钮的值?
基础教程推荐
- WooCommerce 中选定产品类别的自定义产品价格后缀 2021-01-01
- Libpuzzle 索引数百万张图片? 2022-01-01
- 在 Woocommerce 中根据运输方式和付款方式添加费用 2021-01-01
- mysqli_insert_id 是否有可能在高流量应用程序中返回 2021-01-01
- 超薄框架REST服务两次获得输出 2022-01-01
- XAMPP 服务器不加载 CSS 文件 2022-01-01
- 在 PHP 中强制下载文件 - 在 Joomla 框架内 2022-01-01
- 通过 PHP SoapClient 请求发送原始 XML 2021-01-01
- 如何在 PHP 中的请求之间持久化对象 2022-01-01
- 在多维数组中查找最大值 2021-01-01