-1

I have the following code in jQuery

var fila;
$(document).ready(function(){
   acciones_filas('tbl_producto', 'acciones-activos', productoTable);
   $("#id_producto").val(fila.nProCodigo);
}

function acciones_filas(tabla_id, acciones_id, tabla_objeto, fila)
{
    //click on a row
    $("#"+tabla_id+" tbody").on('click', 'tr', function(){
        $("#"+acciones_id+" .btn").removeAttr('disabled');
        if ( $(this).hasClass('row_selected') ) {
            $(this).removeClass('row_selected');
        }
        else {
            tabla_objeto.$('tr.row_selected').removeClass('row_selected');
            $(this).addClass('row_selected');
        }

        if($('#'+tabla_id+' .row_selected').length < 1)
            $("#"+acciones_id+" button").attr('disabled', 'disabled');

        fila = tabla_objeto.fnGetData(this); 
    });
}

When I click on a row of a table the variable fila must save the value of the selected row, but when I print the result I get and undefined

Teemu
  • 22,918
  • 7
  • 53
  • 106
laviku
  • 531
  • 12
  • 32

1 Answers1

2

On you context, you have two vars fila. One inside the function, other outside. Javascript will try to use the one that is closer. On that case, the argument of the function acciones_filas.

Give a look on point 8 of that link: What is the scope of variables in JavaScript?

Community
  • 1
  • 1
anolsi
  • 529
  • 1
  • 11
  • 21