我想验证动态创建表的每一行的每个选择选项。
我试图做一个for循环,但是它只得到第一行的值。这是我的代码:
function GetCellValues() {
var table = document.getElementById('criteriatbl');
for (var r = 1, n = table.rows.length; r < n; r++) {
var results = document.getElementById("results");
var strRes = results.options[results.selectedIndex].text;
alert(strRes);
}
}
html表格
<table border="1" width="" id='criteriatbl'>
$i = 0;
foreach($result as $criteria) {
$i+=1;
echo
"
<tr><td align='center'>$i</td>
<td align='center'> <label for='criteria'> $criteria->catID </label></td>
<td>$criteria->category</td>
<td style='word-wrap: break-word'>$criteria->critDesc</td>
<td><select id='results' name='results[]'>
<option value='Select'>Select</option>
<option value='Compliant'>Compliant</option>
<option value='OFI'>OFI</option>
<option value='AOC'>AOC</option>
<option value='MinorNC'>Minor NC</option>
<option value='MajorNC'>Major NC</option>
<option value='NA'>NA</option>
</select> </td>
<td> <textarea name='comment[]' value='comment' rows='7' cols='45' placeholder='write something here'></textarea></td></tr>
";
}
?>
</table>
在每一行中,我应该获得用户所选择的每个选项的值。