我有一个jsp页面,我放置了几个单选按钮。
选择单选按钮并单击提交按钮后,它将调用一个javascript函数,该函数需要单选按钮的选定值才能对scriplet执行某些操作。
任何人都可以解决这个问题吗?
<td align="center"><input type="radio" name="radio" id="radio" value="value1"></td>
<td align="center"><input type="radio" name="radio" id="radio" value="value2"></td>
<td align="center"><input type="radio" name="radio" id="radio" value="value3"></td>
<td ><a onclick="Javascript:delete();"><span>Delete</span></a></td>
<script language="javascript" type="text/javascript">
function delete()
{
<% String str= here i want that selected radio buttons value%>
}
</script>
答案 0 :(得分:0)
<script language="javascript" type="text/javascript">
function deleteme() {
var values = document.getElementsByName('radio');
for ( var i = 0, length = values.length; i < length; i++) {
if (values[i].checked) {
// do whatever you want with the checked radio
alert(values[i].value);
// only one radio can be logically checked, don't check the rest
break;
}
}
}
</script>
<td align="center"><input type="radio" name="radio" id="radio" value="value1">value1</td>
<td align="center"><input type="radio" name="radio" id="radio" value="value2">value2</td>
<td align="center"><input type="radio" name="radio" id="radio" value="value3">value3</td>
<td><a onclick="deleteme();">Delete</a></td>