Variable inside button with dynamic onclick?

0
var variable = $.parseJSON(variable);

$('#tabla_servicios').append('<tr><td>'+variable.dato1+'</td><td>'+variable.dato2+'</td><td>'+variable.dato3+'</td><td><button onclick="EliminaServicio()" class="btn btn-warning"><i class="fa fa-trash-o"></i>Eliminar</button></td></td></tr>');

How can I enter? variable.dato4 within event onclick="EliminaServicio()

I do it this way onclick="EliminaServicio(variable.dato4)" but I interpret it as plain text

    
asked by Javier Antonio Aguayo Aguilar 20.04.2017 в 23:40
source

2 answers

1

You could concatenate the value, taking into account that:

If the number is dato4 , the concatenation would be like this

$('#tabla').append('<tr><td>'+variable.dato1+'</td><td>'+variable.dato2+'</td><td>'+
  variable.dato3+'</td><td><button onclick="EliminaServicio('+ variable.dato4+')" 
   class="btn btn-warning"><i class="fa fa-trash-o"></i>Eliminar</button></td></td></tr>');

If the data type is a cadena , the concatenation would be like this, note the "" quotes before and after the concatenation.

$('#tabla').append('<tr><td>'+variable.dato1+'</td><td>'+variable.dato2+'</td><td>'+
 variable.dato3+'</td><td><button onclick="EliminaServicio("'+variable.dato4+'")" 
  class="btn btn-warning"><i class="fa fa-trash-o"></i>Eliminar</button></td></td></tr>');
    
answered by 20.04.2017 / 23:52
source
0

You could try this:

onclick="EliminaServicio("+variable.dato4+")"
    
answered by 20.04.2017 в 23:47