dpus81500574 2019-06-17 07:23
浏览 61

如何验证动态创建的表的每一行?

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.

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 HFSS 中的 H 场图与 MATLAB 中绘制的 B1 场 部分对应不上
    • ¥15 如何在scanpy上做差异基因和通路富集?
    • ¥20 关于#硬件工程#的问题,请各位专家解答!
    • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
    • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
    • ¥30 截图中的mathematics程序转换成matlab
    • ¥15 动力学代码报错,维度不匹配
    • ¥15 Power query添加列问题
    • ¥50 Kubernetes&Fission&Eleasticsearch
    • ¥15 報錯:Person is not mapped,如何解決?