I would like to validate each select option for each row of my dynamically created table.
I tried to do a for loop but it is only getting the value of the first row. Here is my code:
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
<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>
At each row I should be getting the value of each of the selected option by the user.