I have completed if I pass a variable id but now I want to pass name to the same function when I click on a image. This is my code:
for (var i = 0; i <friend_data.length; i++) {
results += '<div class = "clicker" id = "'+friend_data[i].id+'" onclick="javascript:testId(this.id,'+ friend_data[i].name+')"><img src="https://graph.facebook.com/' + friend_data[i].id + '/picture" height="30" width="30">' + friend_data[i].name + '</div>';
}
and
function testId(id, friend_data[id].name ){
alert(id);
alert(friend_data[i].name);
}
The alert(friend_data[i].name); does not show because it's wrong. Please help me to correct it.
Please look in even onclick it's the right ways to pass variable?
friend_data[id].nameis not a valid parameter name. (mothereff.in/js-variables)