Value of cells in html table

0

I have the following function but only obtains the values of the first row of the body of the table:

function manipulaTabla(){
var valor=$('#tablaProductoUnidad tr').find('td').eq(1).html();
document.getElementById('prod_descrip').value=valor;
}

How do I get the values of the other rows when I click

I put this function in the event onclic of the body of the table

Html:

<tbody id="tablaProductoUnidad" onclick="manipulaTabla()">
    <tr>
        <%
            ProductoUnidad prodUni=new ProductoUnidad();
                LinkedList<EntProductoUnidad> listaProdUni = prodUni.ListarProducto("", 0);
                for (int i=0;i<listaProdUni.size();i++)
                {
                    out.println("<tr >");
                    out.println("<td>" +listaProdUni.get(i).getProd_cod()+"</td>");
                    out.println("<td align="+"left"+">" +listaProdUni.get(i).getProd_nom()+"</td>");
                    out.println("<td align="+"left"+">" +listaProdUni.get(i).getUni_nombre()+"</td>");
                    out.println("<td align="+"left"+">"+listaProdUni.get(i).getPu_cantidad()+"</td>");
                    out.println("<td align="+"left"+">"+listaProdUni.get(i).getPu_minimo()+"</td>");
                    out.println("<td align="+"left"+">"+listaProdUni.get(i).getPu_maximo()+"</td>");
                    out.println("<td align="+"left"+">"+listaProdUni.get(i).getPu_costo()+"</td>");
                    out.println("<td align="+"left"+">"+listaProdUni.get(i).getPu_precionormal()+"</td>");
                    out.println("<td align="+"left"+">"+listaProdUni.get(i).getPu_precioespecial()+"</td>");
                    out.println("<td >" +"<button class=\"btn btn-primary\" id='"+"btnAct"+i+"' onclick='"+
                    "prodModi()'"+" value='"+listaProdUni.get(i).getProd_cod()
                    + "' data-toggle=\"tooltip\" title=\"Actualizar\">"
                            + "<span class=\"glyphicon glyphicon-pencil\"></span></button>"
                    + "<span > </span>"
                    + "<button class=\"btn btn-primary\"  data-toggle=\"tooltip\" title=\"Eliminar\">"
                            + "<span class=\"glyphicon glyphicon-floppy-remove\">"
                            + "</span></button>");
                    out.println("</tr>");
                }
        %>
    </tr>
</tbody>
    
asked by Leo T 27.09.2017 в 20:39
source

2 answers

1

You could do the following

  $('#tablaProductoUnidad tr').click(function(){
        var tds = $(this).find('td');
        var array_valores =  Array();

        for(var i =  0; i < tds.length; i++){
            array_valores.push($(tds[i]).html());
        }

        $("#prod_descrip").val(array_valores.toString());
    });
    
answered by 27.09.2017 / 23:13
source
1

with this you are looking for all the tr of your table $ ('#ProductBoard tr');

Once you have all your tr, you assign the event .click

Once you add the event, you search for all the td th selected $ (this)

and then you go through all the td's

I update the function so that at the time of clicking on the th, I will send you the information of the td

$(function(){
    var valor=$('#tablaProductoUnidad tr');
    valor.click(function(){
        $.each($(this).find('td'), function(x,y){
           alert($(this).html());
        });
    });    
 });

example: link

Greetings !!!

the league is the same only that it has an update, click Apply local draft version

    
answered by 27.09.2017 в 22:26