Two things. First you need to wrap i
in a closure to store the value that you want. Second [temp]
will not select a DOM element, you will need to do that differently.
for (var i = 0; i < 3; i++) {
var temp = "link" + i;
document.getElementById(temp).onclick = (function(t) {
return function (e) {
alert("You just clicked link: " + t);
};
})(i);
}