Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

128
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!