PHP中怎样获取radio单选框的值

PHP中怎样获取radio单选框的值,第1张

html 代码:

<form action="indexphp" method="post"><!--get方法也是可以的--!>

    <input type="radio" name="sex" value="f"> 女

    <input type="radio" name="sex" value="m"> 男

    <input type="submit" name="submit" value="提交"> 

</form

两个radio控件的name属性必须是一样的

indexphp代码:

$_POST['sex'];//就是单选框选中的  如果使用的是get方法,那么使用 $_GET['sex'];

上面的只是简单地例子,可以参考一下

radio不是有个name属性的么,你只要获取那个naem属性,就会获得对应的radio值啦。看你用什么框架啊,struts1和struts2有点点不同。不过都可以用requestgetParameter("name")这种方式来获得。呵呵

这样写好些吧:

<form onsubmit="return check(this);" >

<input type=radio name="a" value=0>0

<input type=radio name="a" value=1>1

<input type=submit value="提交">

</form>

<script   type="text/javascript">

function   check(formObj)

{

      for(var   i=0;i<formObjalength;i++)

      {         

               if(formObja[i]checked)

               {

               //alert("单选框选中:   "   +   formObja[i]value);

               return   true;

               }

      }   

      alert("单选框未选中");

      return   false;

}   

</script>

radio标签的取值方法如下:

<html:radio   property="userRole"   value="operator"   onclick="radioValue()"/>

<html:radio   property="userRole"   value="admin"   onclick="radioValue()"/>

<script   language="javascript">      

                        function   radioValue(){

                                 var   obj   =   documentalluserRole;

                                 if(obj){

                                       for(var   i=0;i<objlength;i++){//适合length>=2时,当objlength==null时,可以直接取objvalue值

                                             if(obj[i]checked){

                                                   alert(obj[i]value);

                                                   break;

                                             }

                                       }

                                 }         

                        }      

</script>

所生成的网页类似于这样

<form method="post" action="当前页面的地址">

<input type="radio" name="userress_id" id="radio" value="address_id1" />电话:xxx

<input type="radio" name="userress_id" id="radio" value="address_id2" />电话:xxx

</form>

然后最后面改为:

<php

$userress_id = $_POST["userress_id"];

if($userress_id == null)

exit();

$userress_id = $userress_id > 0

>

没看到input 有这种写法,你可以这样,

<input type="radio" name="appointmentRadio" value="1"><span>aa</span>

<input type="radio" name="appointmentRadio" value="2"><span>bb</span>

选择了一个radio那么文本值就是$(":radio:checked + span")text();

以上就是关于PHP中怎样获取radio单选框的值全部的内容,包括:PHP中怎样获取radio单选框的值、求教jsp中怎么获取到提交的表单中被选择的那个radio的值、js获取radio属性的值等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/web/10218736.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-05-06
下一篇 2023-05-06

发表评论

登录后才能评论

评论列表(0条)

保存