Reputation: 27
I've rendered a table using Jquery's DataTable library. Within this datatable I've rendered hyperlink anchors with an onclick event that calls a javascript function. I need to pass more than one parameter to these functions.
I'm able to pass one parameter to the function but I'm unable to pass the variables as two separate parameters. See below code. E.g The value of the GuestID parameter in the emailGuest function takes both GuestID and email e.g. 84a09eeb-9d8d-43cb-9719-e597fc5ad215,[email protected]*
DataTable hyperlink render section
data: null, render: function (data, type, row )
{
return "<a href='#' class='btn btn-danger' onclick= DeleteData('" + row.id + "'); >Delete</a>";
}
},
{
data: null, render: function (data, type, row) {
return "<a href='#' class='btn btn-default' onclick= emailGuest('" + row.id + ',' + row.email + "'); >Email</a>";
}
},
]
});
});
emailGuest Function
function emailGuest(GuestID,email) {
$('#GuestEmail').modal('show');
document.getElementById("emailID").value = GuestID;
document.getElementById("emailAddress").value = email;
}
Upvotes: 0
Views: 8350
Reputation: 6747
Your piece of code wrote both variables in one because you missed some '
in there (', '
changed to "', '"
):
data: null, render: function (data, type, row )
{
return "<a href='#' class='btn btn-danger' onclick= DeleteData('" + row.id + "'); >Delete</a>";
}
},
{
data: null, render: function (data, type, row) {
return "<a href='#' class='btn btn-default' onclick= emailGuest('" + row.id + "', '" + row.email + "'); >Email</a>";
}
},
]
});
});
Upvotes: 1