I have a table, and the last column in the table has a checkbox, when the user clicks on a a check box, i want to pass a row value to a different function, but when i do this, the code doesn't seem to be firing, am i missing something ?
function GetContractors(companyName) {
var workforce = companyName;
$.ajax({
type: 'GET',
url: '@Url.Action("getContractors","Permit")',
contentType: "application/json; charset=utf-8",
dataType: "json",
data: { "workforce": workforce },
success: function (result) {
$("#mainData").empty();
$.each(JSON.parse(result),
function (i, item) {
var row = i + 1;
$("#mainData").append(
"<tr>" +
"<td id='process_" + row + "'" + ">" + item.ContractorName + "</td>" +
"<td bgcolor= " + "'" + cellColour1 + "'" + " id='process_" + row + "'" + ">" + parseJsonDate(item.InductionExpiry) + "</td>" +
"<td bgcolor= " + "'" + cellColour + "'" + " id='process_" + row + "'" + ">" + parseJsonDate(item.InsuranceExpiry) + "</td>" +
"<td id='Action" + row + "'" + ">" +
"<checkbox id='checkbox' class='btn btn-xs btn-success " +
"'" + "onclick='SelectedUser(" + item.ContractorName + ")" +
"'" + ">" + "<i class='glyphicon glyphicon-trash" +
"'" + "></i>" + "</checkbox>" + " " +
"</tr>");
});
},
error: function (result) {
alert(result);
}
});
};
function SelectedUser(name)
{
alert(name);
}
want to pass a row value to a different functionYou are just passing{ "workforce": workforce },Am I missing something?item.ContractorNameis sayjohn, javascript will see the onclick handler code asSelectedUser(john), so javascript wil ltry to look for a variable named john which doesnt exists and error will be thrown. TLDR: Hardcoded string argument is missing quotes.