Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

129
Visualizações
Passing multi parameter to Td inline JavaScript function

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

I tried '(" +report.id +","+ report.name +")'

I tried '(" +report.id report.name +")'

but none works, what I am doing wrong here

            $.ajax({
                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>' + report.id + '</td>';
                        html += '<td>' + report.name + '</td>';
                        html += "<td><a onClick='removeUser(" +report.id + report.name +")'" + "'> Remove </a></td>";
                        html += '</tr>';
                    });
                    $('#users').html(html);
                },


        function removeUser(id, name) {
            alert("ID: "+ id + "Name: "+ name)
        }
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

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

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

html += `<td><a href="#" onClick='removeUser(${report.id}, "${report.name}")'> 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.

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda