Ok, so I have a template which I am using to print a couple of users to a table.
function PrintUsers(item) {
$.template('userList', '<tr onClick="OnUserPressed(${Identifier})">\
<td>${Firstname}</td>\
<td>${Lastname}</td>\
</tr>');
$.tmpl('userList', item).appendTo("#UserTableContainer");
}
When I press a user I want his/hers unique identifier to be passed to a function called OnUserPressed which I am declaring in the template. The code below is just a test to see if it actually passes the data to the function.
function OnUserPressed(Identifier) {
alert(Identifier);
}
My problems are these: When I press the first value in the table I get “Uncaught SyntaxError: Unexpected token ILLEGAL”. When I press any other value in the table I get “Uncaught ReferenceError: xxx is not defined” where xxx is their unique identifier. So it actually retrieves the ID but I still get an error.
Any thoughts?
You probably need to pass the identifier to the
OnUserPressedfunction as a string.Try wrapping the
${Identifier}template variable with single quotes:Edit: Responding to comment about single quotes.
Inside your template string you can escape the single quotes by preceeding them with a backslash: