如何将已检查的单选按钮部分传递给jsp的操作

时间:2011-05-19 06:45:15

标签: java html jsp

<table style="width: 100%; margin-left: 5px;" align="center">
<tr>
    <td style="width: 250px; ">
    <input type="radio" name="radio1" id="radio1" onclick="chkOut();" /> Create Child Component </td>
    <td>
 <input type="radio" name="radio1" id="radio12" onclick="checkOut();"/> Add Component  From Another Asset
 </td>
    </tr>
</table>

var formObj=document.forms[0];
    formObj.action="ArcheTypeDevice.in?&status=AddComponent&SelectedText="+txt;
    formObj.submit();

2 个答案:

答案 0 :(得分:0)

function onCallForInterview()
{
var selectedIds;
var count=0;
for (i=0; i<document.frm.check1.length; i++)
{
if (document.frm.check1[i].checked==true)
{
if(count==0){
selectedIds=document.frm.check1[i].value; 
count=count+1; 
}
else
selectedIds=selectedIds+","+document.frm.check1[i].value;
}
}
alert(selectedIds);  
document.frm.action="<%=contextPath%>/SearchCandInfo?    action=selectcanforinterview&ids="+selectedIds;
document.frm.submit();
}

如果您能够为每个单选按钮分配唯一值,则可以使用此功能。

答案 1 :(得分:0)

您需要为输入元素指定

<form action="someServletUrl" method="post">
    <input type="radio" name="action" value="create" />Create child
    <input type="radio" name="action" value="add" />Add component
    <input type="submit" />
</form>

在servlet中,只需按常规方式获取所选值:

String action = request.getParameter("action");

if ("create".equals(action)) {
    // "Create child" is selected.
} else if ("add".equals(action)) {
    // "Add component" is selected.
}

// ...

不需要令人讨厌的JavaScript黑客攻击,这些浏览器无法在禁用JavaScript的浏览器上运行。