Get row and column item from a dynamic html table

0

Good morning, I set up a dynamic html table with information from a SQL table. In the following structure:

Thistablehasafilterfieldoftheagencieslistedcode:

    <script>
        function myBusca() {
 
            var input, filter, table, tr, td, i;
            input = document.getElementById("myInput");
            filter = input.value.toUpperCase();
            table = document.getElementById("myTable");
            tr = table.getElementsByTagName("tr");

            for (i = 0; i < tr.length; i++) {
                td = tr[i].getElementsByTagName("td")[0];
                if (td) {
                    if (td.innerHTML.toUpperCase().indexOf(filter) > -1) {
                        tr[i].style.display = "";
                    } else {
                        tr[i].style.display = "none";
                    }
                }
            }
        }
    </script>

I need to click on the icon of each line to get the agency name and its code and send it to a TextBox field I'm trying with the following script:

    <script type="text/javascript">
        function myFunction() {
            var x = document.getElementById("cidade").value;
            document.getElementById("<%=txtCidadeAgencia.ClientID %>").value = x;
        }
    </script>

<td style='vertical-align: middle;'>" +
 "<input id='cidade' name='cidade' " +
 "type='hidden' value='{0}'>" +
 "<a href= \"#\"" +
 "class=\"btn btn-default\" " +
 "onclick='myFunction()' data-toggle='modal' " +
 "data-target='#myModal' data-dismiss='modal'>" +
 "<i src=\"#\" class='fa fa-hand-pointer-o'></i></a>" +
 "</td></tr>"

But I can not, I guess I have to get the index of the line to get the selection fields. Someone could give me an orientation.

Thank you.

    
asked by anonymous 20.10.2017 / 15:28

1 answer

1

Solution:

Icon code:

 html.AppendFormat(
                    "<td style='vertical-align: middle;'>" +
                    "<a href= \"#\"" +
                    "class=\"btn btn-default\" " +
                    "onclick='myFunction(\"{0}\")' data-toggle='modal' " +
                    "data-target='#myModal' data-dismiss='modal'>" +
                    "<i src=\"#\" class='fa fa-hand-pointer-o'></i></a>" +
                    "</td></tr>", item.CidadeAgencia);

Function to get the selected item in the table, and send to a TextBox field:

    <script type="text/javascript">
        function myFunction(cidade) { 
           document.getElementById("<%=txtCidadeAgencia.ClientID %>").value = cidade;
        }
    </script>

Thank you LP. Gonçalves

    
20.10.2017 / 22:08