Ramco Ramco

Ramco Ramco

  • 441
  • 3.4k
  • 522.8k

Value not getting printed

Jun 20 2023 5:33 AM

Hi

 I have below code . When i get cell value printed it shows [object HTMLTableCellelement]

Secondly i want to get dropdown selected text value not id.

<script>
        var ddl = document.getElementById("ddlBook");
        ddl.addEventListener("change", function () {
            var selectedValue = ddlBook.value;

            var table = document.getElementById("tbldata"); 

            for (var i = 0; i < table.rows.length; i++) {
                var row = table.rows[i];
                var cell = row.cells[7]; 
                alert(cell);
                if (cell.innerHTML === selectedValue) {
                    cell.style.backgroundColor = "yellow"; 
                } else {
                    cell.style.backgroundColor = ""; 
                }
            }
        });
    </script>

Thanks


Answers (1)