JSP中怎样获取radio的值

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了JSP中怎样获取radio的值相关的知识,希望对你有一定的参考价值。

我用JSP写了一个简单页面(search.jsp),包括一个text,一个submit,三个radio。然后在text输入字符串,然后根据radio的不同做不同的处理。返回的是同一个页面。代码如下:

<i><%@page language="java" import="java.util.*"%></i>

<center>
<form action="search.jsp">
<input type="text" name="keyword" value=<%=request.getParameter("keyword")%> >
<input type="submit" value="Search" style= "center"></form><br/>

<label>Simple Matching</label><input type="radio" checked="checked" name="identype"value="1" />
<label>OR Matching</label><input type="radio" name="identype" value="2" />
<label>AND Matching</label><input type="radio" name="identype" value="3" />

<%
String b = request.getParameter("keyword");
String indentity = request.getParameter("identype");%>

运行结果是可以读取b的值,但是indentity是null。(从其他页面跳转过来的时候可以显示“1”,但是一按“search”返回的就是null。)哪位大神可以帮我下吗?感激不尽!

你可以在页面后面加参数额 用js获取到radio的值 然后在另一个页面就能取到了 参考技术A 你好,jsp获取可以使用requst,也可以使用seesion获取。

JavaScript中获取radio的值

单选按钮的代码如下:
<body>
<input name="q" type="radio" value="a" checked />
<input name="q" type="radio" value="b" />
<input name="q" type="radio" value="c" />
</body>
要求很简单,就是取出value的值。用于switch语句。
能用document.write();显示出也行,不要网上的if语句。
由于要实现功能特殊,请不要在input 后添加事件,可以再外层的form中添加。

1、radio为单选按钮,一般单选按钮有多个可供选择的项,而只能选择一个,比如男、女
2、那么给radio标签里面设定一个id或者class属性
3、在js里面,可以通过checked这个属性来判断哪一个radio标签被选择,
4、这样就可以获取到radio标签的值,然后根据标签的值进行判断,保存/插入数据库等操作
参考技术A <HTML>
<HEAD>
<TITLE> 可用鼠标拖动的层 </TITLE>
</HEAD>

<BODY>
<input name="q" type="radio" value="a" checked />
<input name="q" type="radio" value="b" />
<input name="q" type="radio" value="c" />
<script>
var $ = function(x)return document.getElementById(x)
var set = function()
var obj = document.getElementsByTagName('input');
for(var i=0;i<obj.length;i++)
obj[i].onclick = function()
alert(this.value)



set();
</script>

</BODY><HTML>
参考技术B <body>
<form name="abc">
<input name="q" type="radio" value="a" checked />
<input name="q" type="radio" value="b" />
<input name="q" type="radio" value="c" />
</body>

document.write(abc.q);本回答被提问者采纳
参考技术C function getRadioValue(radioName)

var radios = document.getElementsByName(radioName);
if(!radios)
return '';
for (var i = 0; i < radios.length; i++)

if (radios[i].checked)
return radios[i].value;

return '';
参考技术D <html>
<head>
<script type="text/javascript" language="javascript">
function Foo()
var selectedIndex = -1;
var form1 = document.getElementById("form1");
var i = 0;
for (i=0; i<form1.q.length; i++)
if (form1.q[i].checked)
selectedIndex = i;
alert("您选择项的 value 是:" + form1.q[i].value);
break;


if (selectedIndex < 0) alert("您没有选择任何项"); </script>
</head>
<body>
<form id="form1" action="" method="">
<input type="radio" name="q" value="a" checked>
<input type="radio" name="q" value="b">
<input type="radio" name="q" value="c"> <br/>
<input type="button" value="检查选择项" onclick="Foo()">
</form>
</body>
</html>

以上是关于JSP中怎样获取radio的值的主要内容,如果未能解决你的问题,请参考以下文章

jsp中怎样获得表单中radio的回显信息?

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

thinkphp中怎样获取radio单选框的值(单选框较多)

jsp中选择单选框改变下面显示的值,这个代码如何实现

jsp中怎样获取选择栏修改前和修改后的值

在servlet中怎样获取jsp中下拉列表中的值