Retrieve double GridView javascript

0

The following code points to the event change of a textbox (column 3).

I want to recover the value in a asp:TextBox of a GridView (Column 5)

$("#<%=GridEdos.ClientID%> [id*='txtBox']").change(function () {


     var tr = $(this).parent().parent();
     var ValEsta = $("td:eq(5)", tr).html(); 

     $("td:eq(4) span", tr).html(parseFloat($(this).val()) + ValEsta); 
});

The idea is to add both values and put the sum of both. However what I get is (I hope to be clear) the value of column 3 followed by a text box and in the value that I look for.

If in var ValEsta I receive the text box, how do I point to the value inside that box?

    
asked by Kate2707 18.01.2017 в 23:44
source

2 answers

1

Finally it was like:

            var tr = $(this).parent().parent();

            //Recibo los objetos hijos que en este caso es un input
            var ValEsta = $("td:eq(5)", tr).children();

            //Recibo el valor y además reemplazo de manera recursiva todas las comas
            var txt = ValEsta.val().replace(/,/g, '');

            //Convierto a numero para poder sumarlos
            $("td:eq(4) span", tr).html(parseFloat($(this).val()) + parseFloat(txt));
    
answered by 19.01.2017 / 19:13
source
0

The result of the image indicates that in fact the variable ValEsta and the line:

$("td:eq(4) span", tr).html(parseFloat($(this).val()) + ValEsta);

They are actually getting the HTML code and not the values from the text fields.

To obtain the values of the text fields you can use:

// Obtener el valor de un campo de texto.
var miNumero = $('#txt_num').val();

Source: Response to Get the value in an input text box .

In your code, try changing html to val ; like this:

$("#<%=GridEdos.ClientID%> [id*='txtBox']").change(function () {

     var tr = $(this).parent().parent();
     var ValEsta = $("td:eq(5)", tr).val();

     // Revisa en la consola de tu navegador el resultado.
     console.log(ValEsta); 
     console.log($("td:eq(4) span", tr).val());

     $("td:eq(4) span", tr).val(parseFloat($(this).val()) + ValEsta); 
});

However, check that you are getting the text field.

    
answered by 19.01.2017 в 18:12