我的jsp文件中有一个表,这个表有一个N
radiobuttons
列,其属性为name="radioA"
,然后我为每个radiobutton
迭代到找到所选的radiobutton
:
function findRadioSelected(){
var radioButtons = document.getElementsByName("radioA");
for(var y = 0; y < radioButtons.length; y++){
if(radioButtons[y].checked){
var cont = y;
return cont;
}
}
return -1;
}
在同一个表的另一列中,我有一个带<select>
个选项的N
项,每个id
项的select
属性为[0-N],因为我需要找到radiobutton
checked
,然后获取与select
匹配的radiobutton
项:
function buscarActualizarFitir(){
var counts = findRadioSelected(); //Getting the number of radiobutton checked
alert(counts);
if(counts >= 0){
var radioButtons = document.getElementsByName("radioA");
var idFitir = radioButtons[counts].id; //Geting the id of the radiobutton checked
var e = document.getElementById(counts).selectedIndex; //Getting the selected index of the select item
var x = document.getElementById(counts).options; //Getting the options of the select item
var idSuperGrupo = x[e].index; //Error Line, I'm trying to get the number of the index of the option seleted in the select item...
}
}
但我收到以下错误:
未捕获的TypeError:无法读取未定义的属性“未定义”
[编辑]:
<select>
项的ID实际存在。
function findRadioSelected(){
var radioButtons = document.getElementsByName("radioA");
for(var y = 0; y < radioButtons.length; y++){
if(radioButtons[y].checked){
var cont = y;
return cont;
}
}
return -1;
}
function buscarActualizarFitir(){
var counts = findRadioSelected(); //Getting the number of radiobutton checked
alert(counts);
if(counts >= 0){
var radioButtons = document.getElementsByName("radioA");
var idFitir = radioButtons[counts].id; //Geting the id of the radiobutton checked
var e = document.getElementById(counts).selectedIndex; //Getting the selected index of the select item
var x = document.getElementById(counts).options; //Getting the options of the select item
var idSuperGrupo = x[e].index; //Error Line, I'm trying to get the number of the index of the option seleted in the select item...
}
}
<html>
<head></head>
<body>
<button type="button" id="botonConsultar" onclick="buscarActualizarFitir();"
<span>Action!</span>
</button>
<table align="center">
<tr style="height: 40px;">
<th align="center" width="25%">Selección</th>
<th align="center" width="25%">Unidad de Negocio</th>
<th align="center" width="25%">Producto (Supergrupo)</th>
<th align="center" width="25%">Producto (Subgrupo)</th>
</tr>
<tr style="background-color: rgb(249,249,249)">
<td style="text-align: center;" width="25%">
<p><input id='255' name="radioA" value='255' type="radio" /></p>
</td>
<td style="text-align: center;" width="25%">
ASDASDASDASD
</td>
<td style="text-align: center;" width="25%">
<select id="0">
<!-- OPTIONS -->
</select>
</td>
<td style="text-align: center;" width="25%">
<select id="sub0">
<!-- OPTIONS -->
</select>
</td>
</tr>
<tr style="background-color: rgb(240,241,241)">
<td style="text-align: center;" width="25%">
<p><input id='194' name="radioA" value='194' type="radio" /></p>
</td>
<td style="text-align: center;" width="25%">
ASDASDASDASD
</td>
<td style="text-align: center;" width="25%">
<select id="1">
<!-- OPTIONS -->
</select>
</td>
<td style="text-align: center;" width="25%">
<select id="sub1">
<!-- OPTIONS -->
</select>
</td>
</tr>
<tr style="background-color: rgb(249,249,249)">
<td style="text-align: center;" width="25%">
<p><input id='1003' name="radioA" value='1003' type="radio" /></p>
</td>
<td style="text-align: center;" width="25%">
ASDASDASD
</td>
<td style="text-align: center;" width="25%">
<select id="2">
<!-- OPTIONS -->
</select>
</td>
<td style="text-align: center;" width="25%">
<select id="sub2">
<!-- OPTIONS -->
</select>
</td>
</tr>
<tr style="background-color: rgb(240,241,241)">
<td style="text-align: center;" width="25%">
<p><input id='1002' name="radioA" value='1002' type="radio" /></p>
</td>
<td style="text-align: center;" width="25%">
ASDASDASDASD
</td>
<td style="text-align: center;" width="25%">
<select id="3">
<!-- OPTIONS -->
</select>
</td>
<td style="text-align: center;" width="25%">
<select id="sub3">
<!-- OPTIONS -->
</select>
</td>
</tr>
</table>
</body>
</html>