Assign value to table row cell

0

I have the following function that retrieves the selected row of a table:

function cambios(){
    var tds = $(this).find('td');
}

I want to modify the values of that row and show them in the table, I was doing it this way but it does not work:

tds[3].val("nuevoValor");

also:

$(tds[i]).html()='nuevoValor';

This way also but it does not come out, in this case I want to change the value to the third cell of that row:

$(tds[2]).html('45'); 

I am relying on a function that I use to retrieve data from a row and assign it to several input, but now I want to modify the row of the table that I select.

The function is as follows

function alertas(){
        var tds = $(this).find('td');
        var array_valores =  Array();

        for(var i =  0; i < tds.length; i++){
            array_valores.push($(tds[i]).html());
        }
        $("#prod_codigo").val(array_valores[0].toString());
        $("#prod_descrip").val(array_valores[1].toString());
        $("#PROD_UNIDAD").val(array_valores[2].toString());
        $("#pu_cantidad").val(array_valores[3].toString());
        $("#pu_minimo").val(array_valores[4].toString());
        $("#pu_maximo").val(array_valores[5].toString());
        $("#pu_costo").val(array_valores[6].toString());
        $("#pu_precionormal").val(array_valores[7].toString());
        $("#pu_precioespecial").val(array_valores[8].toString());
}
    
asked by Leo T 05.10.2017 в 20:25
source

1 answer

0

<td> is a "normal" label, not a input for this reason you can not assign any value to it by .val() , and in your second option you are having a syntax problem.

$(tds[i]).html('nuevoValor');

I hope you serve, greetings!

    
answered by 05.10.2017 в 20:27