Why does not OnClick work on my td? [closed]

0

I have the following code in jquery , which adds a row to a table

var fila = "<tr><td>" + $.trim(idProduct) + "</td>";
fila += "<td>" + $.trim(response.d.nombreProducto) + "</td>";
fila += "<td onclick='OpenModal(" + $.trim(idProduct) + ");'>XXXX XXXX XXXX XXXX</td>";
fila += "<td><center><input type='checkbox'></center></td>";
fila += "<td><a id='tableccant'>1</a></td>";
fila += "<td><a id='tablecprice'>" + response.d.precio8 + "</a></td>";
fila += "<td><a id='tablecdescc'>0</a></td>";
fila += "<td>IVA</td>";
fila += "<td>RIVA</td>";
fila += "<td>TOTAL</td>";
fila += "<td><a class='text-danger delete'><span class='glyphicon glyphicon-remove'></span></a></tr>";
var ElementoHTML = $(fila);
$('#TableProducts').append(ElementoHTML);

Which I receive some values by ajax , in order to create that row in the table.

Now within a column of that row, I have an event onclick to which I sent a parameter that in this case is a id .

This parameter is received in another function of jquery , which is as follows.

// Función para abrir la ventana modal de las caracteristicas
function OpenModal(Product) {
    console.log(Product);
    $("#addcaract").modal();
    $("#nameProduct").text("Producto: " + Product);
    $("#priceProduct").text("Precio: ");
    $("#ivaProduct").text("IVA: ");
    $("#totalProduct").text("Total: ");
    $("#ContentPlaceHolder1_DropTerminado").val("XXX");
    $("#ContentPlaceHolder1_DropTapiz").val("XXX");
    $("#CaractCubierta").val("X");
    $("#CaractPersonalizacion").val("X");
    $("#CaractMarca").val("X");
    $("#CaractOpcion").val("X");
}

My problem is that when I click, it sends me the following error.

Uncaught SyntaxError: Invalid or unexpected token

That's the only thing that shows me, you will have some solution for my problem

    
asked by Miguel 12.07.2017 в 22:28
source

1 answer

2

SOLUTION

I commented to them that my problem had to do with the quotes where the parameter was sent, my solution was to change the quotes of the parameter in the following way.

'<td onclick="OpenModal(\''+idProduct+'\');">XXXX XXXX XXXX XXXX</td>';
    
answered by 12.07.2017 в 22:53