0

what is wrong in with my script. it throws error message table.rows[i] is undefined. iam new to jquery thanks in advance :)

update: sorry for the lack of info, error occurs in this line "table.rows[i].cells[3].onclick"

$(document).ready(function () {
    var index, table = document.getElementById('resultset');

    for (var i = 1; i < table.rows.length; i++) {
        table.rows[i].cells[3].onclick = function () {
            $.ajax({
                type: 'POST',
                url: 'Getdetail',
                datatype: "json",
                data: {
                    mydata: table.rows[i].cells[0]

                },
                success: function (data) {
                    alert(data);
                }

            });
        };

    }
});
  • You really should provide a [mcve] so that we can reproduce the problem, and when quoting an error message about a variable that appears multiple times in the code: Say which instance the error is about! – Quentin Jun 18 '17 at 13:17
  • javascript array start with index 0 try with for (var i = 0; i < table.rows.length; i++) i think that in the last iteration loop overflow – JFouad Jun 18 '17 at 13:18
  • @JFouad — It is not unusual to want to skip the header row of a table, and you're wrong about the last iteration overflowing. – Quentin Jun 18 '17 at 13:18
  • sorry for the lack of info, i added the exact location of the error. i tried the said duplicate issue but its different. – Jerome Holasca Jun 18 '17 at 13:26
  • I think you have to change your method in accessing specific cell of your table. – andre_northwind Jun 19 '17 at 01:42
  • I think you have to change your method in accessing specific cell of your table. Use ` table.getElementsByTagName("tr") instead of table.rows[i], as well as use getElementsByTagName("td") on every element instead of rows[i].cells[0] – andre_northwind Jun 19 '17 at 02:27

0 Answers0