Passing multi parameter to Td inline JavaScript function

Passing one parameter ( to removeUser function works fine, but when I want to pass two parameter ( and I get Uncaught SyntaxError: Invalid or unexpected token.

I tried ‘(" +","+ +")’

I tried ‘(" +")’

but none works, what I am doing wrong here

                url: "xxx",
                type: "GET",
                contentType: "application/json;charset=utf-8",
                dataType: "json",
                success: function (result) {
                    var html = '';
                    $.each(result, function (key, report) {
                        html += '<tr>';
                        html += '<td>' + + '</td>';
                        html += '<td>' + + '</td>';
                        html += "<td><a onClick='removeUser(" + +")'" + "'> Remove </a></td>";
                        html += '</tr>';

        function removeUser(id, name) {
            alert("ID: "+ id + "Name: "+ name)

>Solution :

You need commas between the parameters, and you need quotes only around

It’s much easier to write this using a template literal rather than concatenation.

html += `<td><a href="#" onClick='removeUser(${}, "${}")'> Remove </a></td>`;

Also, since you’re doing this with an a element, you should set its href so it doesn’t try to link to another page after running the onclick function.

Leave a Reply